【问题标题】:How to restart the message consumer in Spring Integration?如何在 Spring Integration 中重启消息消费者?
【发布时间】:2013-08-08 21:22:42
【问题描述】:

我的消费者,例如当异常发生或 ActiveMQ 失败时,应该重新启动正在使用来自 ActiveMQ fromChannel 的消息的服务激活器。如何为以下 spring 集成上下文执行此操作?

 <!-- RECEIVER. message driven adapter -> jmsInChannel -> activator. -->

<si:channel id="fromChannel"/>

<int-jms:message-driven-channel-adapter id="messageDrivenAdapter"
    channel="fromChannel" destination="forward" connection-factory="connectionFactory"
    max-concurrent-consumers="2" auto-startup="true" acknowledge="auto" extract-payload="false" />

<si:service-activator id ="activator" 
    input-channel="fromChannel"
    ref="messageService" 
    method="process"/>

<bean id="messageService" class="com.ucware.ucpo.forward.jms.MessageService"/>

我的第一个想法是使用Retry Advice 并添加到服务中,但不确定这是否是未处理异常的正确解决方案。如果 ActiveMQ 服务器关闭,我也希望接收器重新启动。

【问题讨论】:

    标签: spring asynchronous activemq messaging spring-integration


    【解决方案1】:

    message-driven-channel-adapter 中的侦听器容器会在失去与代理的连接时自动继续尝试重新连接。

    如果您设置了 `acknowledge="transacted"',则消息将在出现异常时回滚,并且代理将重新提交。

    有状态的重试建议将允许您在多次重试后放弃并采取其他一些操作(但您也可以将其配置到 ActiveMQ 本身中,它会在多次传递尝试后将消息发送到 DLQ)。

    【讨论】:

    【解决方案2】:

    看到你的帖子我立刻想到了this video。这很好地了解了如何通过自身监控和控制 SI 应用程序。

    此外,您应该查看ApplicationEvent SI 文档。

    将所有这些粘合在一起,您可以使用 JMX 监控 JMS 消息适配器,并通过发送有关问题的 ApplicationEvent 来停止和重新启动它。关于捕获异常,这取决于您实际要处理的异常。我会创建一个 errorChannel 来接收组件抛出的异常,并创建一个新服务来在收到错误后重新启动这些组件。

    利用Spring Retry 在 SI 中的功能实现您的想法。

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 1970-01-01
      • 2020-03-28
      • 1970-01-01
      • 2014-07-03
      • 2020-04-30
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      相关资源
      最近更新 更多