File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ # Message producer
2+
3+ You can choose how to send messages either using a transport directly or with the client.
4+ Transport gives you the access to all transport specific features so you can tune things where the client provides you with easy to use abstraction.
5+
6+ ## Transport
7+
8+ ``` php
9+ <?php
10+
11+ /** @var Symfony\Component\DependencyInjection\ContainerInterface $container */
12+
13+ /** @var Enqueue\Psr\PsrContext $context */
14+ $context = $container->get('enqueue.transport.context');
15+
16+ $context->createProducer()->send(
17+ $context->createQueue('a_queue'),
18+ $context->createMessage('Hello there!')
19+ );
20+ ```
21+
22+ ## Client
23+
24+ The client is shipped with two types of producers. The first one sends messages immediately
25+ where another one (it is called spool producer) collects them in memory and sends them ` onTerminate ` event (the response is already sent).
26+
27+
28+
29+ ``` php
30+ <?php
31+
32+ /** @var Symfony\Component\DependencyInjection\ContainerInterface $container */
33+
34+ /** @var \Enqueue\Client\ProducerInterface $producer */
35+ $producer = $container->get('enqueue.producer');
36+
37+ // message is being sent right now
38+ $producer->send('a_topic', 'Hello there!');
39+
40+
41+ /** @var \Enqueue\Client\SpoolProducer $spoolProducer */
42+ $spoolProducer = $container->get('enqueue.spool_producer');
43+
44+ // message is being sent on console.terminate or kernel.terminate event
45+ $spoolProducer->send('a_topic', 'Hello there!');
46+
47+ // you could send queued messages manually by calling flush method
48+ $spoolProducer->flush();
49+ ```
50+
51+ [ back to index] ( ../index.md )
Original file line number Diff line number Diff line change 2525 - [ Quick tour] ( bundle/quick_tour.md )
2626 - [ Config reference] ( bundle/config_reference.md )
2727 - [ Cli commands] ( bundle/cli_commands.md )
28+ - [ Message producer] ( bundle/message_producer.md )
2829 - [ Message processor] ( bundle/message_processor.md )
2930 - [ Job queue] ( bundle/job_queue.md )
3031 - [ Consumption extension] ( bundle/consumption_extension.md )
You can’t perform that action at this time.
0 commit comments