PHP code example of tomcizek / symfony-prooph-asynchronous-router
1. Go to this page and download the library: Download tomcizek/symfony-prooph-asynchronous-router 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/ */
tomcizek / symfony-prooph-asynchronous-router example snippets
return [
Prooph\Bundle\ServiceBus\ProophServiceBusBundle::class => ['all' => true],
TomCizek\AsynchronousRouter\ProophAsynchronousRouterBundle::class => ['all' => true],
];
declare(strict_types = 1);
namespace YourApp\Infrastructure\Rabbit;
use DateTime;
use OldSound\RabbitMqBundle\RabbitMq\Producer;
use Prooph\Common\Messaging\Message;
use Prooph\Common\Messaging\MessageConverter;
use Prooph\Common\Messaging\MessageDataAssertion;
use TomCizek\AsynchronousRouter\AsynchronousMessageProducerBridge;
final class RabbitAsynchronousMessageProducerBridge implements AsynchronousMessageProducerBridge
{
/** @var Producer */
private $producer;
/** @var MessageConverter */
private $messageConverter;
public function __construct(Producer $producer, MessageConverter $messageConverter)
{
$this->producer = $producer;
$this->messageConverter = $messageConverter;
}
public function publishWithRoutingKey(Message $message, string $routingKey): void
{
$stringMessage = $this->convertMessageToString($message);
$this->producer->publish($stringMessage, $routingKey);
}
private function convertMessageToString(Message $message): string
{
$messageData = $this->messageConverter->convertToArray($message);
MessageDataAssertion::assert($messageData);
$messageData['created_at'] = $message->createdAt()->format(DateTime::ATOM);
return json_encode($messageData);
}
}