Announcement Announcement Module
No announcement yet.
Variation of the RecipientListRouter or ErrorMessageExceptionTypeRouter Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Variation of the RecipientListRouter or ErrorMessageExceptionTypeRouter

    I need a router that is essentially a RecipientListRouter that only sends to the channel of the first selector that accepts the message. This would be similar to the ErrorMessageExceptionTypeRouter, but matches based off of a selector instead of a type of Exception. Does this router exist or do I need to implement a custom router?

  • #2

    You can use here <recipient-list-router> as well as you want:
    HTML Code:
    <recipient-list-router input-channel="inputChannel">
    	<recipient selector-expression="payload.class.simpleName.contains('Exception')" channel="exceptionChannel"/>
    	<recipient selector-expression="@exceptionResolver.accept(payload)" channel="exceptionChannel2"/>
    So, you should have more experience in SpEL

    Good luck!

    Artem Bilan
    Last edited by Artem Bilan; Mar 29th, 2012, 06:24 AM.


    • #3
      Maybe I'm mistaken, but I thought the documentation indicated that the message would be sent to both exceptionChannel and exceptionChannel2 if both selector-expressions evaluated to true. I need the message to be sent only to the channel associated with the first selector-expression that evaluates to true.

      Did I misunderstand the documentation?


      • #4
        message would be sent to both exceptionChannel and exceptionChannel2
        It depends on your selector-expression

        However if you want:
        to be sent only to the channel associated with the first selector-expression that evaluates to true
        than you should implement your own router logic in some POJO-method. It may be based on ErrorMessageExceptionTypeRouter#getChannelKeys

        Your wish brakes recipient-list-router concepts...


        • #5
          I'm not asking to change the recipient-list-router. I understand its purpose, however there is a desire to have an additional router that behaves similar to how recipient-list-router associates a channel to a ExpressionEvaluatingSelector. However, instead of sending to each selector that evaluates to true it only sends to the first selector that evaluates to true.

          I'm looking for a substitute for Apache Camel's RouteBuilder. With it you have the ability to do the following:
                .when(simple("${body.status} == 'COMPLETE'"))
                .when(simple("${property.message.wasTouched} || ${body.type} == 'POLICY'"))
          Where it would be great in Spring Integration for this to have namespace support and look similar to:

          <int:spel-eval-router id="customRouter" input-channel="PROCESS_A" default-output-channel="PROCESS_D">
             <int:recipient channel="PROCESS_B" selector-expression="payload.status('COMPLETE')"/>
             <int:recipient channel="PROCESS_C" selector-expression="headers.containsKey('touched') and payload.type('POLICY')"/>
          My preference is to use Spring Integration, but there is a strong push for Apache Camel as it is perceived to have better routing capabilities.

          Let me know your thoughts.


          • #6
            I almost added some functionality that would have addressed your case. The idea was to include 'max-recipients' as an attribute on the recipient-list-router. Then it would take up to MAX (which could be just 1, as you need) starting with the selector expressions in the order provided.

            If you think that seems like a decent solution, feel free to open a JIRA issue. It would be a trivial implementation.

            In the meantime, you should be able to accomplish this with a fairly simple script (any JVM scripting lang can be used with our router) or even SpEL.