PHPackages                             prooph/psb-zeromq-producer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. prooph/psb-zeromq-producer

ActiveLibrary[Queues &amp; Workers](/categories/queues)

prooph/psb-zeromq-producer
==========================

ZeroMQ Message Producer for Prooph Service Bus

v0.3(10y ago)6214[1 issues](https://github.com/prooph/psb-zeromq-producer/issues)BSD-3-ClausePHPPHP &gt;=5.5

Since Sep 27Pushed 7y ago5 watchersCompare

[ Source](https://github.com/prooph/psb-zeromq-producer)[ Packagist](https://packagist.org/packages/prooph/psb-zeromq-producer)[ Docs](http://getprooph.org/)[ RSS](/packages/prooph-psb-zeromq-producer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (5)Used By (0)

ZeroMQ message dispatcher for ProophServiceBus
==============================================

[](#zeromq-message-dispatcher-for-proophservicebus)

[![Build Status](https://camo.githubusercontent.com/63ce5cd43f2dca57eea41b8ff2eaf2c469eaaa4a0ed71095432b46cd3d53bd28/68747470733a2f2f7472617669732d63692e6f72672f70726f6f70682f7073622d7a65726f6d712d70726f64756365722e737667)](https://travis-ci.org/prooph/psb-zeromq-producer)[![Coverage Status](https://camo.githubusercontent.com/c5d00d5cab2c7ef8fca3e309abd8c903b2e1b38f1e2eb667660eb7d6dc8b6f52/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f70726f6f70682f7073622d7a65726f6d712d70726f64756365722f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/prooph/psb-zeromq-producer?branch=master)[![Gitter](https://camo.githubusercontent.com/abe08b740a4156153736f791393ec4da6619c4be73212e75769f52edacc0e2b5/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667)](https://gitter.im/prooph/improoph)

Use [ZeroMQ](http://zeromq.org/) as message producer for [Prooph Service Bus](https://github.com/prooph/service-bus). Works together with bus types: CommandBus, EventBus.

Important
---------

[](#important)

This library will receive support until December 31, 2019 and will then be deprecated.

For further information see the official announcement here:

Requirements
============

[](#requirements)

PHP doesn't come with native support for ZeroMQ however there is an extension `ext-zmq` instructions are available on the ZMQ website for the PHP bindings.

Installation
============

[](#installation)

So after `ext-zmq` is installed on your server/development machine you're ready for the next step! Composer will be able to install prooph zeromq producer in seconds if not quicker. Run the following command to install via composer.

`composer require prooph/psb-zeromq-producer:~0.2`

Command/Event Bus (PUB/SUB)
===========================

[](#commandevent-bus-pubsub)

To construct your Command/Event bus you'll need to have a server running ZMQ with [`ZMQ::SOCKET_SUB`](http://php.net/manual/en/class.zmq.php#zmq.constants.socket-sub) this will then receive the messages from the producer.

For basic tutorial on PUB/SUB:

### Usage Examples

[](#usage-examples)

```
$container = new Container;
$container['config'] = [
    'prooph' => [
        'zeromq_producer' => [
            'dsn' => 'tcp://127.0.0.1:5555', // ZMQ Server Address.
            'persistent_id' => 'example', // ZMQ Persistent ID to keep connections alive between requests.
            'rpc' => false, // Use as Query Bus.
        ]
    ]
];

$factory = Prooph\ServiceBus\Message\ZeroMQ\Container\ZeroMQMessageProducerFactory;
$zmqProducer = $factory($container);

// Setup complete, now to add it to the prooph service bus.

$commandBus = new Prooph\ServiceBus\CommandBus();
$router = new Prooph\ServiceBus\Plugin\Router\CommandRouter();
$router->route('ExampleCommand')
    ->to($zmqProducer);

$commandBus->utilize($router);
$echoText = new ExampleCommand('It works');
$commandBus->dispatch($echoText);

// Now check your server to make sure it received this command.

```

Query Bus (REQ/REP)
===================

[](#query-bus-reqrep)

To construct your Query bus you'll need to have a ZMQ server running with [`ZMQ::SOCKET_REP`](http://php.net/manual/en/class.zmq.php#zmq.constants.socket-rep) this will then receive the messages from the producer and MUST reply as part of the REQ/REP specification.

For basic tutorial on REQ/REP:

### Usage Examples

[](#usage-examples-1)

```
// file: CLIENT.php

$container = new Container;
$container['config'] = [
    'prooph' => [
        'zeromq_producer' => [
            'dsn' => 'tcp://127.0.0.1:5556', // ZMQ Server Address.
            'persistent_id' => 'example', // ZMQ Persistent ID to keep connections alive between requests.
            'rpc' => true, // Use as Query Bus.
        ]
    ]
];

$factory = Prooph\ServiceBus\Message\ZeroMQ\Container\ZeroMQMessageProducerFactory;
$zmqProducer = $factory($container);

// Setup complete, now to add it to the prooph service bus.

$queryBus = new Prooph\ServiceBus\QueryBus();
$router = new Prooph\ServiceBus\Plugin\Router\QueryRouter();
$router->route('ExampleQuery')
    ->to($zmqProducer);

$queryBus->utilize($router);
$getText = new ExampleQuery('Hello Server.');
$promise = $queryBus->dispatch($getText);

$promise->then(function ($response) {
    var_dump($response); // string "Hello Client."
});

exit(0);

// file: SERVER.php
