NAZEHA
NAZEHA

Reputation: 455

spring integration: error-channel : the first exception prevent the rest of messages to be handled

Need help in error handling in a chain during file:splitter and http:outbound-gateway. Now if there is any exception present in the error message when we receive status-code=400, 500 ... , I want that to be handled in the service activator of error-channel and continue with the other splitted messages.

When we receive exception, it is handled in the service activator, but the other splitted messages is not handled.

the chain:

<int-file:inbound-channel-adapter> ---><int-file:splitter> ---> <int-http:outbound-gateway>

for each line read from a file we should call a WS, so when we receive error msg (status code 400, or 500) we should send it by mail and continue calling ws for the other messages.

the code is like this:

<int-file:inbound-channel-adapter
    directory="/META-INF/tmp" id="filesIn" channel="toSplitter">
    <int:poller fixed-delay="1000" error-channel="error.channel"  />
</int-file:inbound-channel-adapter>

<int-file:splitter input-channel="toSplitter"
    output-channel="router" />

<int:recipient-list-router id="recipentRouter" input-channel="router">

    <int:recipient channel="type1.channel.request"
        selector-expression="headers['file_name'].startsWith('${type1}')" />
    <int:recipient channel="another.type1.channel"
        selector-expression="headers['file_name'].startsWith('${type1}')" />
    <int:recipient channel="type2.channel.request"
        selector-expression="headers['file_name'].startsWith('${type2}')" />
    <int:recipient channel="anothertype2.channel.request"
        selector-expression="headers['file_name'].startsWith('${type2}')" />

</int:recipient-list-router>


<int-http:outbound-gateway 
    request-channel="type1.channel.request"
    url="${url}"
    http-method="PUT" expected-response-type="java.lang.String"      charset="UTF-8"
    reply-timeout="5000" reply-channel="changesim.channel.reply">

</int-http:outbound-gateway>

Upvotes: 1

Views: 854

Answers (1)

Gary Russell
Gary Russell

Reputation: 174769

You need to handle the errors after the splitter.

One solution is to make type1.channel.request a QueueChannel (add a <int:queue/> child element), then put a <poller/> on the http gateway, with the error channel.

The splitter/router will put the split messages in the queue and the poller will pull them out one at a time.

Another solution (if you don't want to use a queue channel for some reason) is to put a mid-flow <gateway/> with an error channel after the splitter - the gateway would be referenced from a service activator.

Upvotes: 1

Related Questions