Skip to content

Commit 397f384

Browse files
Add documentation for producer events
1 parent 3435039 commit 397f384

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,49 @@ If you need to use a custom class for a producer (which should inherit from `Old
316316

317317
The next piece of the puzzle is to have a consumer that will take the message out of the queue and process it accordingly.
318318

319+
#### Producer Events ####
320+
321+
There are currently two events emitted by the producer.
322+
323+
##### BeforeProducerPublishMessageEvent #####
324+
This event occurs immediately before publishing the message. This is a good hook to do any final logging, validation, etc. before actually sending the message. A sample implementation of a listener:
325+
326+
```php
327+
namespace App\EventListener;
328+
329+
use OldSound\RabbitMqBundle\Event\BeforeProducerPublishMessageEvent;
330+
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
331+
332+
#[AsEventListener(event: BeforeProducerPublishMessageEvent::NAME)]
333+
final class AMQPBeforePublishEventListener
334+
{
335+
public function __invoke(BeforeProducerPublishMessageEvent $event): void
336+
{
337+
// Your code goes here
338+
}
339+
}
340+
```
341+
342+
##### AfterProducerPublishMessageEvent #####
343+
This event occurs immediately after publishing the message. This is a good hook to do any confirmation logging, commits, etc. after actually sending the message. A sample implementation of a listener:
344+
345+
```php
346+
namespace App\EventListener;
347+
348+
use OldSound\RabbitMqBundle\Event\AfterProducerPublishMessageEvent;
349+
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
350+
351+
#[AsEventListener(event: AfterProducerPublishMessageEvent::NAME)]
352+
final class AMQPBeforePublishEventListener
353+
{
354+
public function __invoke(AfterProducerPublishMessageEvent $event): void
355+
{
356+
// Your code goes here
357+
}
358+
}
359+
```
360+
361+
319362
### Consumers ###
320363

321364
A consumer will connect to the server and start a __loop__ waiting for incoming messages to process. Depending on the specified __callback__ for such consumer will be the behavior it will have. Let's review the consumer configuration from above:

0 commit comments

Comments
 (0)