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

  • ErrorHandler and errorChannel

    Im looking into the error handling of integration to achieve the following: When an exception occurs, I'd like to store the original payload (in some format, assume XML) along with the error. (why the payload ? -> I like self-healing / auto recovery concepts.. )

    In order todo so, I have two options (right?)

    1) give the endpoint an error-handler that implements the ErrorHandler interface:
    public interface ErrorHandler {
    	void handle(Throwable t);
    Do you see any issues to have handle like
         void handle(Message<?> message, Throwable t);
    This gives the option to log the original message / payload when an error occurs.

    2) Grab the error off the errorChannel

    I'd prefer to do this as I am able to write a single error handler that stores the required payload at a single spot, in a single way. I'd expect a similar interface as the ErrorHandler interface and have read (documentation) that it gives ErrorMessages.

    Somehow this is not working at my side and I could not simply figure out the way the errorChannel works.

    I configured:
        <bean id="errorMessageHandler" class=""/>
        <bean id="ldapMessageErrorHandler" class="org.joiningtracks.his.service.ldap.impl.LdapPatientMessageErrorHandler"/>
        <!-- configure spring integration context -->
        <integration:message-bus error-channel="errorChannel"/>
        <integration:channel id="errorChannel" publish-subscribe="true" capacity="500"/>
        <integration:handler-endpoint input-channel="errorChannel" handler="errorMessageHandler" error-handler="ldapMessageErrorHandler">
            <integration:concurrency core="5" max="25" queue-capacity="20" keep-alive="120"/>
    the errorMessageHandler is a simple class that implements the MessageHandler interface and thereafter simply logs the whole (it does not do yet what I intented... that is next)

    At this moment, I don't see any messages coming, so one question is: what is wrong with this configuration ?

    And the other question, does the ErrorMessages give the original payload / message ?

  • #2

    There was no reply for this post?
    One of my handlers generates an exception. This is correctly routed to the error channel which I also was able to correctly handle.
    My question is what happens to the original message that reached the handler that caused the exception?
    Is there a way to get that?



    • #3
      You can check the type of the Exception, and if it's from Spring Integration's Exception hierarchy, and the Exception occurred while a request Message was being handled or delivered, then that request Message should be available in the Exception (it would not be available if the error occurred before the Message was available e.g. during Message creation).

      Here's the basic idea:
      if (e instanceof MessagingException) {
          Message<?> failedMessage = ((MessagingException) e).getFailedMessage();
          if (failedMessage != null) {
              // do something...