cerpus/pubsub

Client for RabbitMQ pub-sub

v1.2.0 2023-12-01 14:23 UTC

This package is auto-updated.

Last update: 2024-10-30 01:42:58 UTC


README

Simple publish-subscribe for RabbitMQ and PHP.

Requirements

  • PHP 8.0, 8.1, or 8.2
  • The extensions required by php-amqplib

Installation

composer require cerpus/pubsub

Usage

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();

Future scope

  • Support ext-amqp, queue-interop
  • Handle more exceptions from underlying libraries
  • Support configuring flags like auto-delete, etc.

License

This package is released under the MIT license. See the LICENSE file for more information.