Skip to content

Commit 0f584eb

Browse files
committed
[client] add docs.
1 parent cd11f66 commit 0f584eb

1 file changed

Lines changed: 78 additions & 2 deletions

File tree

docs/bundle/message_processor.md

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Here we just show how to register a message processor service to enqueue. Let's
55

66
* [Container tag](#container-tag)
77
* [Topic subscriber](#topic-subscriber)
8+
* [Command subscriber](#command-subscriber)
89

910
# Container tag
1011

@@ -27,8 +28,8 @@ The tag has some additional options:
2728
2829
# Topic subscriber
2930
30-
There is a `TopicSubscriber` interface (like [EventSubscriberInterface](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php)).
31-
It allows to keep subscription login and process logic closer to each other.
31+
There is a `TopicSubscriberInterface` interface (like [EventSubscriberInterface](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php)).
32+
It is handy to subscribe on event messages. It allows to keep subscription login and process logic closer to each other.
3233

3334
```php
3435
<?php
@@ -67,6 +68,81 @@ class SayHelloProcessor implements PsrProcessor, TopicSubscriberInterface
6768

6869
In the container you can just add the tag `enqueue.client.message_processor` and omit any other options:
6970

71+
```yaml
72+
# src/AppBundle/Resources/services.yml
73+
74+
services:
75+
app.async.say_hello_processor:
76+
class: 'AppBundle\Async\SayHelloProcessor'
77+
tags:
78+
- { name: 'enqueue.client.processor'}
79+
80+
```
81+
82+
# Command subscriber
83+
84+
There is a `CommandSubscriberInterface` interface which allows to register a command handlers.
85+
If you send a message using ProducerV2::sendCommand('aCommandName') method it will come to this processor.
86+
87+
```php
88+
<?php
89+
namespace AppBundle\Async;
90+
91+
use Enqueue\Client\CommandSubscriberInterface;
92+
use Enqueue\Psr\PsrProcessor;
93+
94+
class SayHelloProcessor implements PsrProcessor, CommandSubscriberInterface
95+
{
96+
public static function getSubscribedCommand()
97+
{
98+
return 'aCommandName';
99+
}
100+
}
101+
```
102+
103+
On the command subscriber you can also define additional settings such as queue and processor name:
104+
105+
```php
106+
<?php
107+
use Enqueue\Client\CommandSubscriberInterface;
108+
use Enqueue\Psr\PsrProcessor;
109+
110+
class SayHelloProcessor implements PsrProcessor, CommandSubscriberInterface
111+
{
112+
public static function getSubscribedCommand()
113+
{
114+
return ['queueName' => 'fooQueue', 'processorName' => 'aCommandName'];
115+
}
116+
}
117+
```
118+
119+
There is a possibility to register a command processor which works exclusively on the queue (no other processors bound to it).
120+
In this case you can send messages without setting any message properties at all. Here's an example of such a processor:
121+
122+
In the container you can just add the tag `enqueue.client.message_processor` and omit any other options:
123+
124+
```php
125+
<?php
126+
use Enqueue\Client\CommandSubscriberInterface;
127+
use Enqueue\Psr\PsrProcessor;
128+
129+
class SayHelloProcessor implements PsrProcessor, CommandSubscriberInterface
130+
{
131+
public static function getSubscribedCommand()
132+
{
133+
return [
134+
'processorName' => 'the-exclusive-command-name',
135+
'queueName' => 'the-queue-name',
136+
'queueNameHardcoded' => true,
137+
'exclusive' => true,
138+
];
139+
}
140+
}
141+
```
142+
143+
The same as a topic subscriber you have to tag a processor service (no need to add any options there):
144+
145+
70146
```yaml
71147
# src/AppBundle/Resources/services.yml
72148

0 commit comments

Comments
 (0)