在Mule中采用JMS 传输器进行消息传输,首先要有消息总线的支持,以ActiveMQ为例,详细步骤如下:
1 启动ActiveMQ(详见ActiveMQ)
2 编写发送端配置文件
jms-send-mule-config.xml
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns="http://www.mulesource.org/schema/mule/core/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jms="http://www.mulesource.org/schema/mule/jms/2.2" xmlns:http="http://www.mulesource.org/schema/mule/http/2.2" xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2" xmlns:https="http://www.mulesource.org/schema/mule/https/2.2" xsi:schemaLocation=" http://www.mulesource.org/schema/mule/jms/2.2 http://www.mulesource.org/schema/mule/jms/2.2/mule-jms.xsd http://www.mulesource.org/schema/mule/http/2.2 http://www.mulesource.org/schema/mule/http/2.2/mule-http.xsd http://www.mulesource.org/schema/mule/https/2.2 http://www.mulesource.org/schema/mule/https/2.2/mule-https.xsd http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd"> <jms:activemq-connector name="jmsQueueConnector" specification="1.0.2b" brokerURL="tcp://localhost:61616"/> <jms:activemq-connector name="jmsTopicConnector" specification="1.0.2b" brokerURL="tcp://localhost:61616"/> <stdio:connector name="stdioConnector" messageDelayTime="1234" promptMessage="Please enter something: " /> <model name="jms102bModel"> <service name="jms102bService"> <inbound> <stdio:inbound-endpoint system="IN"/> </inbound> <outbound> <pass-through-router> <jms:outbound-endpoint connector-ref="jmsTopicConnector" topic="backup-reports"/> </pass-through-router> </outbound> </service> </model> </mule>
3 编写接收端配置文件
jms-receive-mule-config.xml
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns="http://www.mulesource.org/schema/mule/core/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jms="http://www.mulesource.org/schema/mule/jms/2.2" xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2" xsi:schemaLocation=" http://www.mulesource.org/schema/mule/jms/2.2 http://www.mulesource.org/schema/mule/jms/2.2/mule-jms.xsd http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd"> <jms:activemq-connector name="jmsConnector" specification="1.0.2b" brokerURL="tcp://localhost:61616"/> <model name="Listing 3.19"> <service name="Backup Reporting Service"> <inbound> <jms:inbound-endpoint topic="backup-reports" connector-ref="jmsConnector"> <jms:jmsmessage-to-object-transformer/> </jms:inbound-endpoint> </inbound> <outbound> <pass-through-router> <stdio:outbound-endpoint system="OUT"/> </pass-through-router> </outbound> </service> </model> </mule>
4 分别启动receive和send,发送端输入信息,接收端将会将输入的信息显示到控制台上。
over