LogoLogo
FeedsIntelligenceEngagementsHelpHome
TRADE360 Integration
TRADE360 Integration
  • Integration Guide
  • RMQ connection
    • Connection and Consumption setup
    • Message Deserializing
    • Market/Bet Message Handling
    • How do I work with TRADE360 feed?
  • Message Structure
    • Message Types Overview
    • Message
    • Events
    • Fixture
    • Competition
    • Markets
    • Bets
    • Participant
    • Livescore
    • Settlements
    • Heartbeat
    • Keep Alive
    • Extra Data
    • Outright Fixture
    • Outright Fixture Market
    • Outright League Fixture
    • Outright League Market
    • Outright Settlements
    • Outright League Settlement
    • Example Messages
    • ProviderMarkets
  • APIs
    • Metadata
    • Subscription
    • Distribution
    • Snapshot
    • Notes and Troubleshooting
  • Enumerations
    • Fixture/Scoreboard Status
    • Subscription
    • Message Types
    • Bet Suspension Reasons
    • Fixture Extra Data
    • Status Description
    • Statistics and Incidents
    • Periods
    • Bet Settlements and Statuses
    • Livescore Extra Data
    • Languages
  • SDK
    • SDK Overview
    • Configuration
    • SDK Installation Guide NodeJS
    • SDK Installation Guide .NET
    • SDK Installation Guide Java
  • Code Samples
    • RMQ Consumer (PHP)
    • RMQ Consumer (GO)
    • RMQ Consumer (Node.js)
    • RMQ Consumer (Python)
    • RMQ Consumer (JavaScript)
    • RMQ Consumer (C#)
Powered by GitBook
On this page

Was this helpful?

  1. Code Samples

RMQ Consumer (PHP)

PreviousSDK Installation Guide JavaNextRMQ Consumer (GO)

Last updated 1 year ago

Was this helpful?

  1. Install PHP: Make sure you have PHP installed on your system. You can download the latest version of PHP from the and follow the installation instructions for your operating system. Alternative and easier way to automatically install PHP with Chocolatey: To install PHP using Chocolatey (choco) package manager on Windows, follow these steps:

    1. Install Chocolatey:

      • Open PowerShell as Administrator.

      • Run the following command to install Chocolatey:

        Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
      • Allow the installation to complete.

    2. Install PHP:

      • Open PowerShell or a new command prompt.

      • Run the following command to install PHP using Chocolatey:

        choco install php
      • Allow the installation to complete.

    3. Verify the PHP installation:

      • Open a new command prompt or PowerShell.

      • Run the following command to check if PHP is installed and get the PHP version:

        codephp -v
      • If PHP is installed successfully, you should see the PHP version information.

  2. Install Composer: Composer is a dependency management tool for PHP. You'll need Composer to install the required dependencies for the code. You can download Composer from the official and follow the installation instructions for your operating system.

  3. Set up the project: Create a new directory for your project and navigate to that directory in your terminal or command prompt.

  4. Create a composer.json file: In the project directory, create a new file called composer.json and paste the following content into it:

{
    "require": {
        "php-amqplib/php-amqplib": "^3.5.4"
    }
}
  1. Install dependencies: Run the following command in your terminal or command prompt to install the required dependencies:

composer install

This command will download and install the necessary packages, including the php-amqplib/php-amqplib package.

  1. Replace <FilesPath>: In the code, you'll notice the placeholder <FilesPath>. Replace it with the actual path where you want to save the JSON files.

  2. Run the code: Save the PHP code in a file with a .php extension (e.g., consumer.php). Open your terminal or command prompt, navigate to the project directory, and run the following command:

php consumer.php

The code will establish a connection to RabbitMQ, consume messages from the queue specified by "_99_", process the messages, and save the JSON files to the specified directory.

Make sure you have the correct RabbitMQ server details (hostname, port, username, password, virtual host) and adjust them in the code accordingly.

Note: The code assumes you have the php-amqplib/php-amqplib package installed via Composer. If you encounter any issues related to missing dependencies, ensure that you've completed the steps to install the dependencies using Composer. Code:

<?php

require_once __DIR__.'/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;

// Set up RabbitMQ connection
$connection = new AMQPStreamConnection("HostName", 5672, "email", "password", "VHOST");
$channel = $connection->channel();

// Set up consumer to receive messages from the queue
$channel->basic_consume("_QUEUE_", '', false, true, false, false, function ($msg) {
    // Convert the message body to a string
    $body = $msg->getBody();

    // Parse the JSON string into an object
    $updateObject = json_decode($body);

    // Serialize the object back to a string, with indentation and line breaks
    $beautifiedUpdate = json_encode($updateObject, JSON_PRETTY_PRINT);

    // Get the current date and time in the UTC +0 time zone
    $utcTime = new DateTime('now', new DateTimeZone('UTC'));

    // Convert the DateTime object to a string in the desired format
    $dateTimeString = $utcTime->format('Y-m-d\TH-i-s\Z');

    // Generate the file path using the formatted date and time string
    $filePath = "C:/Users/tomer.a/Downloads/Consumer/files/" . $dateTimeString . ".json";

    // Save the beautified JSON string to a file
    file_put_contents($filePath, $beautifiedUpdate);
});

while ($channel->is_consuming()) {
    $channel->wait();
}

$channel->close();
$connection->close();

?>
official PHP website
Composer website