sroze / swarrot-bridge
Swarrot bridge for Symfony Message component
Installs: 12
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bridge
Requires
- swarrot/swarrot-bundle: ^1.5@dev
This package is auto-updated.
Last update: 2024-10-29 05:16:22 UTC
README
This bridge allows you to use the great designed Swarrot library to consume and produce messages to various message brokers.
Usage
- Install Swarrot's bridge
composer req sroze/swarrot-bridge:dev-master
- Configure Swarrot Bundle within your application.
# config/packages/swarrot.yaml swarrot: default_connection: rabbitmq connections: rabbitmq: host: 'localhost' port: 5672 login: 'guest' password: 'guest' vhost: '/' consumers: my_consumer: processor: app.message_processor middleware_stack: - configurator: swarrot.processor.signal_handler - configurator: swarrot.processor.max_messages extras: max_messages: 100 - configurator: swarrot.processor.doctrine_connection extras: doctrine_ping: true - configurator: swarrot.processor.doctrine_object_manager - configurator: swarrot.processor.exception_catcher - configurator: swarrot.processor.ack messages_types: my_publisher: connection: rabbitmq # use the default connection by default exchange: my_exchange
Important note: Swarrot will not automatically create the exchanges, queues and bindings for you. You need to manually configure these within RabbitMq (or another connector you use).
- Register producer and processor.
# config/services.yaml services: # ... app.message_producer: class: Sam\Symfony\Bridge\SwarrotMessage\SwarrotProducer arguments: - "@swarrot.publisher" - "@message.transport.default_encoder" - my_publisher app.message_processor: class: Sam\Symfony\Bridge\SwarrotMessage\SwarrotProcessor arguments: - "@message_bus" - "@message.transport.default_decoder"
See that the processor is something Swarrot-specific. As Swarrot's power is to consume messages, we won't use the Message component's command in this context but Swarrot's command. We've configured Swarrot to use this processor in the previous file's configuration.
- Route your messages to the bus
# config/packages/framework.yaml message: routing: 'App\Message\MyMessage': app.message_producer
- Consume your messages!
bin/console swarrot:consume:my_consumer queue_name_you_created