【问题标题】:Spring Integration handle http outbound gateway failuresSpring Integration 处理 http 出站网关故障
【发布时间】:2013-05-24 16:20:51
【问题描述】:

有多个服务器正在监听 activemq。该链被配置为进行 http [出站网关] 调用。假设如果 http 调用由于某种原因失败,则其中一台服务器拾取消息。消息应该放回队列中,以便另一个服务器可以接收消息并进行处理。这可以使用 Spring Integration 来实现吗?我阅读了很多关于 Transaction 的内容,但找不到可行的方法。

【问题讨论】:

    标签: spring spring-integration


    【解决方案1】:

    是的,只需在<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
    • Spring 中的事务只能在单个线程上工作;一旦你移交给另一个线程,当前线程将立即返回容器并提交。在这种情况下,您不能使用 ExecutorChannels 或 QueueChannels。您只需要使用DirectChannels。如果您需要并发,应该使用message-driven-adapter 上的并发设置来处理;这样每条消息都在自己的线程上得到完全处理。
    猜你喜欢
    • 1970-01-01
    • 2013-08-26
    • 1970-01-01
    • 2016-05-07
    • 2022-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    相关资源
    最近更新 更多