--- layout: default parent: "Symfony bundle" title: Message processor nav_order: 5 --- {% include support.md %} # Message processor A processor is responsible for processing consumed messages. Message processors and usage examples described in [consumption/message_processor](../consumption/message_processor.md) Here we just show how to register a message processor service to enqueue. * Transport: * [Register a transport processor](#register-a-transport-processor) * Client: * [Register a topic subscriber processor](#register-a-topic-subscriber-processor) * [Register a command subscriber processor](#register-a-command-subscriber-processor) * [Register a custom processor](#register-a-custom-processor) ## Register a topic subscriber processor There is a `TopicSubscriberInterface` interface (like [EventSubscriberInterface](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php)). It is handy to subscribe on event messages. Check interface description for more possible ways to configure it. It allows to keep subscription and processing logic in one place. ```php 'aCommand', 'queue' => 'the-queue-name', 'prefix_queue' => false, 'exclusive' => true, ]; } } ``` The service has to be tagged with `enqueue.command_subscriber` tag. # Register a custom processor You could register a processor that does not implement neither `CommandSubscriberInterface` not `TopicSubscriberInterface`. There is a tag `enqueue.processor` for it. You must define either `topic` or `command` tag attribute. It is possible to define a client you would like to register the processor to. By default, it is registered to default client (first configured or named `default` one ). ```yaml # src/AppBundle/Resources/services.yml services: AppBundle\Async\SayHelloProcessor: tags: # registers as topic processor - { name: 'enqueue.processor', topic: 'aTopic' } # registers as command processor - { name: 'enqueue.processor', command: 'aCommand' } # registers to no default client - { name: 'enqueue.processor', command: 'aCommand', client: 'foo' } ``` The tag has some additional options: * queue * prefix_queue * processor * exclusive You could add your own attributes. They will be accessible through `Route::getOption` later. # Register a transport processor If you want to use a processor with `enqueue:transport:consume` it should be tagged `enqueue.transport.processor`. It is possible to define a transport you would like to register the processor to. By default, it is registered to default transport (first configured or named `default` one ). ```yaml # config/services.yml services: App\Queue\SayHelloProcessor: tags: - { name: 'enqueue.transport.processor', processor: 'say_hello' } # registers to no default transport - { name: 'enqueue.processor', transport: 'foo' } ``` The tag has some additional options: * processor Now you can run a command and tell it to consume from a given queue and process messages with given processor: ```bash $ ./bin/console enqueue:transport:consume say_hello foo_queue -vvv ``` [back to index](index.md)