如何在 Mule ESB 中保留包含 Java 消息的队列?

How to persist a queue which contains Java Message in Mule ESB?

我在我的 Mule 应用程序中使用 JMS 端点和 Apache ActiveMQ(我遵循了一个教程,但不确定我依赖 JMS 作为端点是否做对了)

<jms:activemq-connector  name="jms-connector" brokerURL="${BrokerURL}" disableTemporaryReplyToDestinations="true" specification="1.1"/>

<jms:endpoint connector-ref="jms-connector" exchange-pattern="one-way" name="UnsortedOrders" queue="UnsortedOrders"/>                
<jms:endpoint connector-ref="jms-connector" exchange-pattern="one-way" name="DestinationEMC" queue="DestinationEMC" />                
<jms:endpoint connector-ref="jms-connector" exchange-pattern="one-way" name="DestinationOriginal" queue="DestinationOriginal"/>  

此时我需要自动存储(保存在磁盘上)与之关联的队列,以便电源故障和其他故障不会永远杀死未完成的进程,并且一旦 mule 再次启动,该进程就会继续。

我以前使用过带标签的 ObjectStore,但我不知道如何将它与 JMS 端点队列绑定。这就是我之前使用 ObjectStore 的方式:

    <spring:bean id="objectStore" class="org.mule.util.store.QueuePersistenceObjectStore"/>




    <until-successful objectStore-ref="objectStore" maxRetries="${MaximumRetry}" secondsBetweenRetries="${RetryInterval}">
        <http:outbound-endpoint address="${ECMURL}" exchange-pattern="one-way">             
            <transformer ref="contentTypeTextXML"/>
        </http:outbound-endpoint>
    </until-successful> 

您不能将对象存储绑定到 JMS 端点。也就是说 - 如果您不覆盖 ObjectStore 实现。

但是,您可以使用 JMS 持久性实现相同的目的。你必须使用事务。

<jms:inbound-endpoint queue="Destination.EMC" connector-ref="jms-connector">
    <jms:transaction action="ALWAYS_BEGIN"/>
</jms:inbound-endpoint>

<http:outbound-endpoint address="${ECMURL}" exchange-pattern="one-way">             
   <transformer ref="contentTypeTextXML"/>
</http:outbound-endpoint>

因此,如果您将消息放入队列,它将尝试 post 到 HTTP,如果失败,它将回滚到队列并重试。当所有尝试都已完成,调用仍不成功时,消息回滚到死信队列,默认ActiveMQ.DLQ

要控制重试消息的次数以及重试之间的延迟,您可以使用 redelivery policy

您可以向代理添加重新交付策略详细信息url。即

tcp://localhost:61616?jms.redeliveryPolicy.maximumRedeliveries=${MaximumRetry}&jms.redeliveryPolicy.redeliveryDelay=${RetryIntervalInMilliseconds}

可以在 Mule ESB blog.

上找到有关如何将 ActiveMQ 重新交付与 Mule ESB 一起使用的很好的解释