简体   繁体   English

ule子-JMS(ActiveMQ)重新连接

[英]Mule - JMS (ActiveMQ) Reconnection

This is my mule flow 1 : 这是我的m子流1

HTTP > Payload String > Logger > JMS /normalqueue

The first flow has an error handling : 第一流程有一个error handling

File (Write a file per message handled) File每条处理的消息写一个文件

Flow 2 : 流程2

JMS /normalqueue > Logger

Recovery flow (Invoked with a groovy script ): 恢复流程 (使用groovy脚本调用):

File (Read file) > File to String > Flow reference (To First Flow again)

This is the XML from Mule: 这是来自Mule的XML:

<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<jms:activemq-connector name="Active_MQ" username="admin" password="admin" brokerURL="tcp://192.168.198.131:61616" validateConnections="true" doc:name="Active MQ" persistentDelivery="true">
    <reconnect blocking="false" frequency="6000"/>
</jms:activemq-connector>
<file:connector name="File" writeToDirectory="C:\errors" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
<flow name="lab-file-catchFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
    <set-payload value="#[message.payloadAs(java.lang.String)]" doc:name="Set Payload"/>
    <logger message="Started message: #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
    <jms:outbound-endpoint queue="activemq" connector-ref="Active_MQ" doc:name="JMS">
        <jms:transaction action="ALWAYS_BEGIN"/>
    </jms:outbound-endpoint>
    <catch-exception-strategy doc:name="Catch Exception Strategy">
        <file:outbound-endpoint path="C:\errors" connector-ref="File" responseTimeout="10000" doc:name="File"/>
    </catch-exception-strategy>
</flow>
<flow name="flow-recovery" initialState="stopped" processingStrategy="synchronous">
    <file:inbound-endpoint path="C:\errors" connector-ref="File" responseTimeout="10000" doc:name="File"/>
    <file:file-to-string-transformer doc:name="File to String"/>
    <logger message=" Recovery message: #[message.payloadAs(java.lang.String)]" level="ERROR" doc:name="Logger"/>
    <flow-ref name="lab-file-catchFlow" doc:name="Flow Reference"/>
</flow>
<flow name="lab-file-catchFlow2" processingStrategy="synchronous">
    <jms:inbound-endpoint queue="activemq" connector-ref="Active_MQ" doc:name="JMS"/>
    <logger message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
</flow>
<flow name="lab-file-catchFlow1" >
    <http:listener config-ref="HTTP_Listener_Configuration" path="/modify" doc:name="HTTP"/>
    <scripting:component doc:name="Groovy">
        <scripting:script engine="Groovy"><![CDATA[            if(muleContext.registry.lookupFlowConstruct('flow-recovery').isStopped())
             {
              muleContext.registry.lookupFlowConstruct('flow-recovery').start();
              return 'Started';
             } else
             {
             muleContext.registry.lookupFlowConstruct('flow-recovery').stop();
             return 'Stopped';
             }]]></scripting:script>
    </scripting:component>
    <set-payload value="#[message.payloadAs(java.lang.String)]" doc:name="Set Payload"/>
    <logger message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
</flow>
  1. I stop service from ActiveMQ , it store a file with the messages from the error handling and I receive the typical error: 我停止了ActiveMQ服务,它存储了包含来自错误处理的消息的文件,并且我收到了典型的错误:

Cannot process event as "Active_MQ" is stopped 由于“ Active_MQ”已停止,因此无法处理事件

  1. Then, I run the ActiveMQ service again and start the recovery flow with a groovy script. 然后,我再次运行ActiveMQ service ,并使用groovy脚本启动恢复流程。 That flow recover all messages, converts to string and return to the first flow to requeue. 该流程恢复所有消息,转换为字符串,然后返回第一个流程以重新排队。

The problem is that mule doesn't detect when service is running again, I need to restart the mule project to detect it. 问题是,当服务再次运行时,ule子无法检测到,我需要重新启动the子项目以对其进行检测。

Is there any way auto detect when the activeMQ is running again with Mule? 有什么方法可以自动检测 activeMQ是否在Mule中再次运行?

By <reconnect-forever/> , Mule will keep re-trying to connect to ActiveMQ 通过<reconnect-forever/> ,Mule将继续尝试重新连接到ActiveMQ

<jms:activemq-connector name="Active_MQ" username="admin" password="admin" brokerURL="tcp://192.168.198.131:61616" validateConnections="true" doc:name="Active MQ" persistentDelivery="true">
    <reconnect-forever/>
</jms:activemq-connector>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM