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

dev-master / 1.0.x-dev 2017-10-08 12:41 UTC

This package is auto-updated.

Last update: 2024-02-29 03:17:29 UTC


README

This bridge allows you to use the great designed Swarrot library to consume and produce messages to various message brokers.

Usage

  1. Install Swarrot's bridge
composer req sroze/swarrot-bridge:dev-master
  1. 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).

  1. 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.

  1. Route your messages to the bus
# config/packages/framework.yaml
    message:
        routing:
            'App\Message\MyMessage': app.message_producer
  1. Consume your messages!
bin/console swarrot:consume:my_consumer queue_name_you_created