I have had the command bus up and running for a while and developed a lot of my application. Now their are some commands I wish to process asynchronously. I have added the BernardMessageProducer and that all seem to work. I would like to only send curtain Commands to the async bus and the rest to be handled locally.
Is this possible and how can I do it. I have already written a command router, but is after the command bus has handled the message .
Thank you
From the readme
If you want to set up a bus that handles all messages async you can do so by attaching a Prooph\ServiceBus\Plugin\MessageProducerPlugin initialized with your message producer of choice to a message bus.
Let's look at a simple example using the psb-zeromq-producer
//app bootstrap
$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);
$commandBus = new \Prooph\ServiceBus\CommandBus();
$messageProducerForwarder = new \Prooph\ServiceBus\Plugin\MessageProducerPlugin($zmqProducer);
$commandBus->utilize($messageProducerForwarder);
$echoText = new ExampleCommand('It works');
$commandBus->dispatch($echoText);
You can also route individual messages to message producer by using a message router plugin.
Note: Prooph\ServiceBus\Plugin\Router\RegexRouter is a good choice if you want to handle all messages of a specific namespace async.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With