jiromm / zf3-rabbitmq
RabbitMQ module for Zend Framework
Installs: 5 409
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 4
Open Issues: 0
Type:module
Requires
- php: ^5.3 || ^7.0
- php-amqplib/php-amqplib: 2.6.*
- zendframework/zend-servicemanager-di: ^1.0
This package is auto-updated.
Last update: 2024-12-13 04:13:00 UTC
README
ZF3 Module for RabbitMQ
Install
composer require jiromm/zf3-rabbitmq
Configure
create configuration with rabbitmq
key as described below:
<?php return [ 'rabbitmq' => [ 'host' => 'localhost', 'port' => 5672, 'login' => 'guest', 'password' => 'guest', ], ]
Make sure the module enabled and try an example below.
Send message
<?php /** * @var \RabbitMQ\Service\RabbitMQ $rabbitmqService * @var \Interop\Container\ContainerInterface $container */ $rabbitMQ = $container->get(\RabbitMQ\Service\RabbitMQ::class); $publisher = new \RabbitMQ\Publisher\WorkQueuePublisher('test_work_queue'); $job = new \RabbitMQ\Job\Job(['some' => 'data']); $rabbitMQ->setPublisher($publisher); $rabbitMQ->push($job);
Receive message
<?php /** * @var \RabbitMQ\Service\RabbitMQ $rabbitmqService * @var \Interop\Container\ContainerInterface $container */ $rabbitMQ = $container->get(\RabbitMQ\Service\RabbitMQ::class); $consumer = new \RabbitMQ\Consumer\WorkQueueConsumer('test_work_queue'); $rabbitMQ->setConsumer($consumer); $rabbitMQ->receive(function (\RabbitMQ\Consumer\Message $message) { echo $message->getBody(); $message->ack(); });