/RabbitMQMessageEnrichBundle

Bundle to enrich messages on a RabbitMQ

Primary LanguagePHPMIT LicenseMIT

ConnectHolland Rabbit MQ Message Enrich Bundle

Disclaimer

This bundle assumes you serialize your messages as json.

Installation

composer require connectholland/rabbit-mq-message-enrich-bundle dev-master

Do no add the bundle to your AppKernel, there is no bundle class (required).

Configuration

Example to enrich messages with a user_id with the information from FoobarBundle:User in user listening and publishing on a channel foo for messages with routing_key bar.

config.yml

old_sound_rabbit_mq:
    connections:
        default:
            ...
    consumers:
        enrich_message:
            connection:       default
            exchange_options: {name: 'foo', type: direct, durable: false}
            queue_options:    {name: '', durable: false, auto_delete: true, exclusive: true, routing_keys:  ['bar']}
            callback:         foobar_consumer
    producers:
        foobar_producer:
            exchange_options: {name: 'foo', type: direct, durable: false}
            queue_options: {name: '', durable: false, auto_delete: true, exclusive: true}

services.yml

services:
    userController:
        class: ConnectHolland\RabbitMQMessageEnrichBundle\Controller\DoctrineEnrichController
        arguments: ["@doctrine", "FoobarBundle:User"]
    foobar_consumer:
        class: ConnectHolland\RabbitMQMessageEnrichBundle\Consumer\EnrichMessageConsumer
        arguments: ["@userController", "@old_sound_rabbit_mq.foobar_producer_producer", "@jms_serializer", "user_id", "user"]

Enitity.User.yml

FoobarBundle\Entity\User:
    exclusion_policy: ALL
    properties:
        id:
            expose: true
        user_id:
            expose: true
        email:
            expose: true
        firstName:
            expose: true
        middleName:
            expose: true
        lastName:
            expose: true

Nested enrichment

You can enrich nested parts of the message, for example foo in the following message:

{ foobar: { foo : "bar" } }

Use dot notation to access the nested items, in this case foobar.foo.