Announcement Announcement Module
Collapse
No announcement yet.
custom routing and dynamic amqp outbound adapter attributes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • custom routing and dynamic amqp outbound adapter attributes

    so I have a use case that requires somewhat unique functionality.

    I understand the concept of message router in spring integration, but from what I understand, the router implementation takes a message and routes it based on conditions to the appropriate channel. IN the examples of custom routers I have seen the output channels are defined in the context.

    My use case involves receiving an AMQP message on one queue (Q1) and then routing the message to another queue (QX). In my application, QX (or its corresponding channel tied to an outbound AMPQ adapter) cannot be predefined in the context. Exchanges, Queues, and Routing keys are created by the application as needed. There could be 1000s of QXs. The decision on which queue to route the message to needs to be made a POJO (instantiated by a service-activator or router) that examines the payload of the message, does a database lookup, and makes a decision on which queue to route the message to.

    Normally, the amqp outbound channel adapter looks like the following. Is there someway for my POJO to set the routing-key and exchange-name attributes of the amqp outbound channel adapter dynamically?

    Code:
    <int-amqp:outbound-channel-adapter channel="channel1"
    		amqp-template="amqpTemplate" exchange-name="someexchange"
    		routing-key="some.routingkey"/>

  • #2
    Yes, you can use the 'exchange-name-expression' and 'routing-key-expression' attributes, both of which accept any valid SpEL. The evaluation context for the expression includes the Message instance so you can use 'payload.someProp' and 'headers.someKey' and so on.

    Comment


    • #3
      ... and - regarding your specific question about a POJO making the decision - you can even invoke the POJO within SpEL by using '@someBean.someMethod(..)' syntax.

      Hope that helps.
      -Mark

      Comment

      Working...
      X