Reagieren is a set of adapters for many different queues systems.
Currently it's hard to have one unique interface to access RabbitMQ, ApacheKafka, IronMQ, etc... So why not having only one common interface and implementing adapters that follows this interfaces? That's the main concept of this library.
Anywhere, that's the beauty of it, you don't depend on a huge framework or any other component. Think about this as a unified way to access message brokers.
Check this producer:
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;
Now check this consumer:
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;
As you can see it's just an adapter that will abstract all the complexity of setting technology specific problems. For instance to put something on a kafka queue we need to:
- Set up the consumer
- Add brokers
- Create a topic
- Select the partition
- Send the payload
But you don't care about partitions, topics, queue balancing, so that's really awesome!
You can produce messages to multiple brokers using Composite\Producer
, see this example:
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;