Reputation: 1539
I have an async gateway with an async executor and an error-channel defined. Also there is a service activator that handles exceptions.
<int:gateway id="myGateway"
service-interface="me.myGateway"
default-request-channel="requestChannel"
async-executor="taskScheduler"
error-channel="errorChannel"/>
<int:service-activator ref="errorChannelMessageHandler" method="handleFailedInvocation"
input-channel="errorChannel"/>
public interface MyGateway {
Future<Object> send(Message message);
}
@Component
public class ErrorChannelMessageHandler {
@ServiceActivator
public Object handleFailedInvocation(MessagingException exception) {
// do some stuff here
return null;
}
}
When an exception is being thrown, the thread blocks, waiting for a reply on the temporary reply channel the gateway has created.
How can I prevent the threads from blocking and when exceptions are thrown to have the error-channel service activator handle the message and perform some custom logic?
Later edit: I am using SI 3.0.3.RELEASE When an error channel is defined for the gateway, if exception occurs it will call this line (no 250 from MessagingGatewaySupport) errorFlowReply = this.messagingTemplate.sendAndReceive(this.errorChannel, errorMessage), which will do a blocking receive on a newly created temporary reply channel(lines 352-367 from MessagingTemplate). Is my service activator for the error-channel responsible for publishing a message on this newly create temporary channel, so the thread won't block on the receive?
Upvotes: 3
Views: 1183
Reputation: 174664
Remove the error-channel so that the original exception is added to the Future
so that the get()
will propagate it.
If you want to do something on the error flow, throw an exception from the error flow so it's available in the Future
, or set reply-timeout
to 0. However, your Future will never get a value or exception in that case.
Upvotes: 1