PHP code example of hellofresh / reagieren

1. Go to this page and download the library: Download hellofresh/reagieren library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hellofresh / reagieren example snippets


use HelloFresh\Reagieren\MessageBroker\RabbitMQ\PHPAmqp\Producer;

(new Producer('127.0.0.1', 5672, 'guest', 'guest'))->produce('example', 'Hello world this is a message');

echo 'Message sent!', PHP_EOL;

use HelloFresh\Reagieren\Message;
use HelloFresh\Reagieren\MessageBroker\RabbitMQ\PHPAmqp\Consumer;

$consumer = new Consumer('127.0.0.1', 5672, 'guest', 'guest');

$callback = function (Message $message) {
    echo 'Received ', $message->getPayload(), PHP_EOL;
};

$consumer->consume(
    'example',
    $callback
);

echo 'Listening...', PHP_EOL;

use HelloFresh\Reagieren\MessageBroker\Composite\Producer;

//... setup RabbitMQ broker
$rabbitProducer = ...;

//... setup Kafka broker
$kafkaBroker = ...;

$configs = [
    'kafka_php' => [
        'topic' => 'example_topic'
    ],
    'rabbit_mq' => [
        'topic' => 'example_exchange'
    ]
];

(new Producer($rabbitProducer, $kafkaBroker))->produce($payload, $configs);

echo 'Message sent!', PHP_EOL;