Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support AMQP #12

Merged
merged 18 commits into from
Aug 6, 2019
Merged

Add support AMQP #12

merged 18 commits into from
Aug 6, 2019

Conversation

peter-gribanov
Copy link
Member

fix #11

Configure queue:

use GpsLab\Domain\Event\Queue\Subscribe\AMQPSubscribeEventQueue;
use GpsLab\Domain\Event\Queue\Serializer\SymfonySerializer;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use Symfony\Component\Serializer\Serializer;
//$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest'); // AMQP connection
//$channel = $connection->channel();
//$symfony_serializer = new Serializer(); // Symfony serializer
//$logger = new Logger(); // PSR-3 logger
$queue_name = 'article_queue';
$format = 'json'; // default: predis
// you can create another implementation of serializer
$serializer = new SymfonySerializer($symfony_serializer, $format);
$queue = new AMQPSubscribeEventQueue($channel, $serializer, $logger, $queue_name);

Subscribe to the queue:

use GpsLab\Domain\Event\Bus\ListenerLocatedEventBus;
use GpsLab\Domain\Event\Listener\Locator\DirectBindingEventListenerLocator;
$locator = new DirectBindingEventListenerLocator();
$bus = new ListenerLocatedEventBus($locator);
$handler = function(ArticleRenamedEvent $event) use ($bus) {
    $bus->publish($event);
};
$queue->subscribe($handler);

You can unsubscribe of the queue:

$queue->unsubscribe($handler);

Make event and publish it into queue:

$event = new ArticleRenamedEvent();
$event->new_name = $new_name;
$queue->publish($event);

@coveralls
Copy link

coveralls commented Aug 6, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling a6e62a4 on peter-gribanov:amqp into 3db48d8 on gpslab:master.

@peter-gribanov peter-gribanov merged commit bbb1332 into gpslab:master Aug 6, 2019
@peter-gribanov peter-gribanov deleted the amqp branch August 6, 2019 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Any future support for RabbitMq?
2 participants