Spring Integration Gateway中的超时表达

时间:2016-05-16 14:55:52

标签: java spring timeout spring-integration

Spring Integration的Gateway元素具有“default-reply-timeout”属性,但无法根据消息本身的数据设置超时值。我可以为每个可能的超时值创建一个网关,然后在运行时为该消息选择一个合适的网关,但这显然是一个讨厌的解决方法。

Release 4.2为TCPOutboundGateway添加了一个“remote-timeout-expression”属性,但该更改没有进入GatewayProxyFactoryBean。

话虽如此,有没有办法在特定于消息的基础上配置超时?如果没有,“remote-timeout-expression”属性是否计划在某个时候被移植到GatewayProxyFactoryBean?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

它目前是一个固定值,不能逐个消息地配置。

我们当然可以考虑这样做,但由于the release candidate is already out,它可能不会进入4.3。

一种可能的解决方法是使用MessagingTemplate而不是网关。您可以设置MessagingTemplate的集合,每个集合配置不同的超时,而不是网关:

 Foo result = this.templateWith10SecondTimeout.convertSendAndReceive(bar, Foo.class);

或者,您可以向网关添加不同的方法,每种方法都有不同的回复超时。

public interface GW {

     Foo waitTenSeconds(Bar bar);

     Foo waitTwentySeconds(Bar, bar);

}

默认超时是默认值,可以在每种方法上设置超时。