Announcement Announcement Module
Collapse
No announcement yet.
PayloadTypeRouter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PayloadTypeRouter

    I have question about how to use this PayloadTypeRouter. The payload is always MessageException (line 57, PayloadTypeRouter). How does it route base on different exception type?

  • #2
    Can you provide a little more information about the Messages that you are routing (specifically regarding their type)?

    It the actual runtime type of payload is always the same and you want to route based on something else, then you might want to consider implementing one of the channel-resolver interfaces or using the @Router annotation.

    If the runtime types are different (e.g. sometimes MessageDeliveryException other times MessageHandlingException), then you can map these types to different channels.

    -Mark

    Comment


    • #3
      I was reading the documentation, and I though it does that already. So yes, I need to implement my own channel resolver. I was looking at the default channel resolver and it would not work as is. Thanks.

      -Kiet

      "To enable global error handling, simply register a handler on that channel. For example, you can configure Spring Integration's PayloadTypeRouter as the handler of an endpoint that is subscribed to the 'errorChannel'. That router can then spread the error messages across multiple channels based on Exception type."


      Originally posted by Mark Fisher View Post
      Can you provide a little more information about the Messages that you are routing (specifically regarding their type)?

      It the actual runtime type of payload is always the same and you want to route based on something else, then you might want to consider implementing one of the channel-resolver interfaces or using the @Router annotation.

      If the runtime types are different (e.g. sometimes MessageDeliveryException other times MessageHandlingException), then you can map these types to different channels.

      -Mark

      Comment


      • #4
        PayloadTypeRouter does route based on the runtime type of the payload for any Message it receives. The documentation is describing a case where for example you want to route MessageHandlingExceptions to an "invalid message channel" and MessageDeliveryExceptions to a "dead letter channel".

        If you want to route based on something other than payload type, then the PayloadTypeRouter is not the right choice. What is your routing decision based upon?

        (note that we are planning to provide some more built-in routers and more powerful binding annotations - so it would be easier to create "mapping" routers based on a value in a MesageHeader attribute, etc.)

        -Mark

        Comment


        • #5
          I guess what you are trying to do is route based on the type of the *root-cause exception* within each error message that you are receiving from the "error channel"?

          -Mark

          Comment


          • #6
            Route by user exception

            it is route base the user exception at run time. Using the Cafe example, I build a map of

            <util:map>
            <entry key="TooHotException" value-ref="TooHotChannel"/>
            <entry key="TooColdException" value-ref="TooColdChanel"/>
            </util:map

            and resolver. It seems to work. Is this the optimal approach? By the way, what is the equivalent of @Router using XML approach?. I am not too fond of annotation.

            public static class MyChannelResolver implements ChannelResolver {

            public MessageChannel resolve(Message<?> message) {
            MessagingException e = (MessagingException) message.getPayload(); Throwable myEx = e.getCause();
            MessageChannel channel = channelMappings.get(myEx.getClass());
            return channel != null ? channel : defaultChannel;
            }
            }


            Originally posted by Mark Fisher View Post

            If you want to route based on something other than payload type, then the PayloadTypeRouter is not the right choice. What is your routing decision based upon?

            -Mark

            Comment


            • #7
              I have added the following two issues based on the feedback in this thread...

              Provide namespace support for routers: http://jira.springframework.org/browse/INT-168

              Provide a root-cause ErrorMessage router: http://jira.springframework.org/browse/INT-169

              Thanks,
              -Mark

              Comment


              • #8
                Currently, the easiest way to use a namespace for confguring a router is to use the <endpoint/> element and specify a "handler-ref" attribute that points to a router bean definition.

                The router bean definition should then be something like this:
                Code:
                <bean id="errorMessageRouter" class="org.springframework.integration.router.SingleChannelRouter">
                    <property name="channelResolver" ref="myChannelResolver"/>
                </bean>
                Hope that helps.
                Mark

                Comment


                • #9
                  One for @Splitter as well

                  The should be an corresponding equivalent for XML support for each notation. I think Spring framework still supports JDK 1.4 so annotation is not always available as an option.

                  Originally posted by Mark Fisher View Post
                  I have added the following two issues based on the feedback in this thread...

                  Provide namespace support for routers: http://jira.springframework.org/browse/INT-168

                  Provide a root-cause ErrorMessage router: http://jira.springframework.org/browse/INT-169

                  Thanks,
                  -Mark

                  Comment


                  • #10
                    We do plan to provide namespace support for each of the handler annotations (e.g. router and splitter) within the 1.0 timeframe. Feel free to vote and/or watch the following issues:
                    router: http://jira.springframework.org/browse/INT-168
                    splitter: http://jira.springframework.org/browse/INT-135

                    Note that the Spring Integration project does require Java 5+.

                    Regards,
                    -Mark

                    Comment

                    Working...
                    X