我有一个异步执行器和定义的错误通道的异步网关。还有一个处理异常的服务激活器。
<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;
}
}
当抛出异常时,线程会阻塞,等待网关创建的临时回复通道上的回复。
如何阻止线程阻塞以及何时抛出异常以使错误通道服务激活器处理消息并执行某些自定义逻辑?
稍后编辑: 我正在使用SI 3.0.3.RELEASE 当为网关定义错误通道时,如果发生异常,它将调用此行(MessagingGatewaySupport没有250) errorFlowReply = this.messagingTemplate.sendAndReceive(this.errorChannel,errorMessage),这将执行阻止在新创建的临时回复通道上接收(来自MessagingTemplate的352-367行)。我的错误通道的服务激活器是否负责在这个新创建的临时通道上发布消息,因此线程不会阻止接收?
答案 0 :(得分:1)
删除错误频道,以便将原始异常添加到Future
,以便get()
传播它。
如果您想对错误流程执行某些操作,请从错误流程中抛出异常,以便Future
中可用,或将reply-timeout
设置为0.但是,您的未来在这种情况下永远不会得到价值或例外。