cerpus / php-pubsub

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cerpus\PubSub

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.

About

License:MIT License


Languages

Language:PHP 94.6%Language:Dockerfile 5.4%