Announcement Announcement Module
Collapse
No announcement yet.
Use bean method in routing-key-expression of a int-amqp:outbound-channel-adapter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Use bean method in routing-key-expression of a int-amqp:outbound-channel-adapter

    Hi

    I'm using a bean to contain a map of transaction types to routing key. I want to call this bean's resolver method (passing the message payload) in the 'routing-key-expression' field of a <int-amp:outbound-channel-adapter>.
    But I cannot find anyway to do this, I've tried various SPEL constructs but either find the expression scope is the GenericMessage which means I can't call another bean, or if use the '#{...}" construct I can access the resolver bean but cannot access the message or the payload.

    Is there anyway to do this?

    Example:
    Code:
       <int-amqp:outbound-channel-adapter channel="outboundChannel" amqp-template="amqpTemplate"
           routing-key-expression="routingKeyResolver.geRoutingKeyFor(payload.type)" />
    
        <!-- Bean for resolving an outgoing transaction to the appropriate routing key -->
        <bean id="routingKeyResolver" class="com.example.RoutingKeyResolver" >
            <property name="routingKeyMap">
                <map>
                    <entry key="create" value="com.example.create"/>
                    <entry key="read" value="com.example.read"/>
                    <entry key="update" value="com.example.update"/>
                    <entry key="delete" value="com.example.delete"/>
                </map>
            </property>
        </bean>
    The above XML produces the following error:
    Code:
    Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'routingKeyResolver' cannot be found on object of type 'org.springframework.integration.message.GenericMessage'

  • #2
    Hi!

    Unfortunately, you can't do it right now. IMO it's a simple bug.
    Please, open a JIRA issue(https://jira.springsource.org/browse/INT) about enhancement 'routing-key-expression' & 'exchange-name-expression' with 'BeanFactoryResolver'. In this case it would look like:
    HTML Code:
    routing-key-expression="@routingKeyResolver.geRoutingKeyFor(payload.type)"
    However there is a workaround for you:
    1. Place before <int-amqp:outbound-channel-adapter> <header-enricher> with the same expression
    2. And in the <int-amqp:outbound-channel-adapter>'s 'routing-key-expression' use the value from that header:
    HTML Code:
    <chain input-channel="outboundChannel">
    	<header-enricher>
    	     <header name="routingKey" expression="@routingKeyResolver.geRoutingKeyFor(payload.type)"/>
    	</header-enricher>
           <amqp:outbound-channel-adapter amqp-template="amqpTemplate" routing-key-expression="headers.routingKey" />
    </chain>
    Take care,
    Artem

    Comment


    • #3
      Raised INT-2999 for this case.

      Thanks for the workaround solution.

      Comment

      Working...
      X