hellofresh / reagieren
A set of adapters for message brokers.
Installs: 150
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 165
Forks: 2
Open Issues: 3
Requires
- php: >=5.4.0
- easyframework/collections: v5.0.0
Requires (Dev)
- codacy/coverage: dev-master
- nmred/kafka-php: ^0.1.5
- php-amqplib/php-amqplib: 2.6.*
- phpunit/phpunit: ~4.8
Suggests
- nmred/kafka-php: Required to use the KafkaPHP Adapter
- php-amqplib/php-amqplib: Required to use the RabbitMQ Adapter
This package is not auto-updated.
Last update: 2021-05-15 00:04:48 UTC
README
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.
Where can we use this?
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.
How to use it?
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!
Producing to multiple brokers
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;