Results 1 to 10 of 10

Thread: PayloadTypeRouter

  1. #1
    Join Date
    Mar 2008
    Posts
    10

    Default 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. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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

  3. #3
    Join Date
    Mar 2008
    Posts
    10

    Default

    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."


    Quote 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

  4. #4
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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

  5. #5
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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

  6. #6
    Join Date
    Mar 2008
    Posts
    10

    Default 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;
    }
    }


    Quote 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

  7. #7
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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

  8. #8
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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

  9. #9
    Join Date
    Mar 2008
    Posts
    10

    Default 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.

    Quote 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

  10. #10
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •