【发布时间】:2013-05-24 16:20:51
【问题描述】:
有多个服务器正在监听 activemq。该链被配置为进行 http [出站网关] 调用。假设如果 http 调用由于某种原因失败,则其中一台服务器拾取消息。消息应该放回队列中,以便另一个服务器可以接收消息并进行处理。这可以使用 Spring Integration 来实现吗?我阅读了很多关于 Transaction 的内容,但找不到可行的方法。
【问题讨论】:
有多个服务器正在监听 activemq。该链被配置为进行 http [出站网关] 调用。假设如果 http 调用由于某种原因失败,则其中一台服务器拾取消息。消息应该放回队列中,以便另一个服务器可以接收消息并进行处理。这可以使用 Spring Integration 来实现吗?我阅读了很多关于 Transaction 的内容,但找不到可行的方法。
【问题讨论】:
是的,只需在<int-jms:message-driven-channel-adapter/> 上设置acknowledge="transacted",并且只要您只使用直接频道(频道上没有<queue/> 或频道调度程序上的task-executor),那么任何失败都会导致消息回滚。
【讨论】:
<int:channel id="UChannel"> <int:dispatcher task-executor="taskExecutor"/> </int:channel> <int-jms:inbound-gateway request-channel="UChannel" request-destination-name="U" extract-request-payload="true" /> <int:chain input-channel="UChannel"> <int-http:outbound-gateway url="http://localhost/u.php?fileid={fileid}" http-method="GET"> <int-http:uri-variable name="fileid" expression="headers.fileid"/> </int-http:outbound-gateway> <int:object-to-string-transformer /> </int:chain>配置了task-executor
ExecutorChannels 或 QueueChannels。您只需要使用DirectChannels。如果您需要并发,应该使用message-driven-adapter 上的并发设置来处理;这样每条消息都在自己的线程上得到完全处理。