jiromm/zf3-rabbitmq

RabbitMQ module for Zend Framework

0.0.2 2016-08-11 12:47 UTC

This package is auto-updated.

Last update: 2020-09-12 18:51:35 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();
});