This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

How to redirect the message to an error channel using spring integration.Page Title Module

Thanks for the reply. I changed that in my java code, but seems like it is still not sending the event to my error channel. I think the problem should be in my xml file, so here's what I am doing in my xml file:

The way it works right now, is that the event passes from the annotator channel to the destination channel. That's all the wiring that is going on in the xml file. So that when the send method is called from one of the classes on the channel ( this is from the same class and method where I want to add the exception handling), it calls the annotator channel, which processes the event and send it to the destination channel which again processes the event using the handleAuditEvent method. Now I want to pop in the error handling code somewhere before the send is called from the java class on the annotator channel. So I put that part

where log is the method where my exception statements are. This does not seem to be writing the error events to the errorChannel, so either I have the error channel configured wrong or I am missing something in my xml file, but not sure.

I put a system.out in that section, but it is not even reaching that part, when I run my junit. It actually errors out while loading the bean definition from the xml file. It gives an out of memory error for the Java heap space, and seems like it is actually erroring out while loading the error Channel beans or something associated with it, like the selector or so. Here is the stack trace:

Comment

Can you please provide a minimal configuration that replicates the problem. The exception you are showing could be caused by any bean within your configuration

Actually it was working fine before I added the part for the error handling. I just added the error handling later on. So this following configuration ( with all my other beans commented out) gives the same exception:

Comment

Looking through the spring integration documentation, I found the following under the section titled 'B.4 Error Handling':

The most important thing to understand here is that the messaging-based error handling will only apply to Exceptions that are thrown by a Spring Integration task that is executing within a TaskExecutor. This does not apply to Exceptions thrown by a handler that is operating within the same thread as the sender (e.g. through a DirectChannel as described above).

Does this mean that since I am using a direct channel, it is not possible for me to be able to do error handling and send the bad messages to the error channel?

In the first scenario inbound messaging gateway by definition encapsulates the entry point to a Messaging system and thus defines the error-channel attribute to allow pluggable error-handling logic.
In the second scenario, you the caller do not own the thread but would like to know if anything wrong happened and that is why the error-channel plays role there.
Basically think of it this way; The caller into the messaging system must handle errors.
When you send message to a DirectChannel you are the caller into the messaging system and thus responsible to handle errors. If you are using gateway such gateway is the caller and thus has capabilities to handle errors. And when thread breakage is part of the messaging flow, each new thread is essentially a caller into a messaging system and provides error-handling capabilities.