Simple publish-subscribe for RabbitMQ and PHP.
- PHP 8.0, 8.1, or 8.2
- The extensions required by php-amqplib
composer require cerpus/pubsub
use Cerpus\PubSub\Connection\ConnectionFactory;
use Cerpus\PubSub\PubSub;
$connectionFactory = new ConnectionFactory('localhost', 5672, 'guest', 'guest', '/');
$pubSub = new PubSub($connectionFactory->connect());
// publish your own messages
$pubSub->publish('some_other_topic', 'some data');
// listen for incoming messages
$pubSub->subscribe('subscriber_name', 'some_topic', function (string $data) {
// do something with the data
echo "$data\n";
});
$pubSub->listen();
- Support ext-amqp, queue-interop
- Handle more exceptions from underlying libraries
- Support configuring flags like auto-delete, etc.
This package is released under the MIT license. See the LICENSE
file for more
information.