Skip to content

Commit d8ccbe5

Browse files
committed
Expand quick tour for Symfony Bundle
According to comments in php-enqueue#884.
1 parent 202de9c commit d8ccbe5

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

Diff for: docs/bundle/quick_tour.md

+42-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ class Kernel extends BaseKernel
5858

5959
## Usage
6060

61-
First, you have to configure a transport layer and set one to be default.
61+
First, you have to configure a transport layer.
62+
You can optionally configure multiple transports if you want to. One of them will automatically become the default,
63+
based on the following:
64+
1. If there is a transport named `default`, then it will become the default.
65+
2. First one specified otherwise.
66+
67+
Default transport's services will be available to you in the usual Symfony container under their respective class
68+
interfaces (see below)
6269

6370
```yaml
6471
# app/config/config.yml
@@ -67,26 +74,47 @@ enqueue:
6774
default:
6875
transport: "amqp:"
6976
client: ~
77+
some_other_transport:
78+
transport: "amqp:"
79+
client: ~
7080
```
7181
72-
Once you configured everything you can start producing messages:
82+
Once you configured everything you can start producing messages.
83+
As stated previously, default transport services are available in container. Here we are using `ProducerInterface` to
84+
produce message to the `default` transport.
7385

7486
```php
7587
<?php
88+
use Enqueue\Client\Message;
7689
use Enqueue\Client\ProducerInterface;
7790
7891
/** @var ProducerInterface $producer **/
7992
$producer = $container->get(ProducerInterface::class);
8093
94+
// If you want a different producer than default (for example the other specified in sample above) then use
95+
// $producer = $container->get('enqueue.client.some_other_transport.producer');
8196
8297
// send event to many consumers
8398
$producer->sendEvent('aFooTopic', 'Something has happened');
99+
// You can also pass an instance of Enqueue\Client\Message as second argument if you need more flexibility.
100+
$properties = [];
101+
$headers = [];
102+
$message = new Message('Message body', $properties, $headers);
103+
$producer->sendEvent('aBarTopic', $message);
84104
85105
// send command to ONE consumer
86106
$producer->sendCommand('aProcessorName', 'Something has happened');
87107
```
88108

89-
To consume messages you have to first create a message processor:
109+
To consume messages you have to first create a message processor.
110+
111+
Example below shows how to create a Processor that will receive messages from `aFooTopic` topic (and only that one).
112+
It assumes that you're using default Symfony services configuration and this class is
113+
[autoconfigured](https://symfony.com/doc/current/service_container.html#the-autoconfigure-option). Otherwise you'll
114+
have to tag it manually. This is especially true if you're using multiple transports: if left autoconfigured, processor
115+
will be attached to the default transport only.
116+
117+
Note: Topic in enqueue and topic on some transports (for example Kafka) are two different things.
90118

91119
```php
92120
<?php
@@ -113,13 +141,16 @@ class FooProcessor implements Processor, TopicSubscriberInterface
113141
}
114142
```
115143

116-
Register it as a container service and subscribe to the topic:
144+
Register it as a container service. Subscribe it to the topic if you are not using autowiring.
117145

118146
```yaml
119147
foo_message_processor:
120148
class: 'FooProcessor'
121149
tags:
122150
- { name: 'enqueue.topic_subscriber' }
151+
# Use the variant below to attach to a specific client
152+
# Also note that if you don't disable autoconfigure, above tag will be applied automatically for default client
153+
# - { name: 'enqueue.topic_subsciber', client: 'some_other_transport' }
123154
```
124155

125156
Now you can start consuming messages:
@@ -128,6 +159,13 @@ Now you can start consuming messages:
128159
$ ./bin/console enqueue:consume --setup-broker -vvv
129160
```
130161

162+
You can select a specific client for consumption:
163+
164+
```bash
165+
$ ./bin/console enqueue:consume --setup-broker --client="some_other_transport" -vvv
166+
```
167+
168+
131169
_**Note**: Add -vvv to find out what is going while you are consuming messages. There is a lot of valuable debug info there._
132170

133171

0 commit comments

Comments
 (0)