Mule JMS Transport之ActiveMQ整合
简单需求:
??? 1.服务端从控制台接收信息转为消息发送之队列.
??? 2.客户端从队列获取消息转换为消息输出到控制台.
mule配置信息如下:
<springs:bean value="${broker.tcp.local.url}"/> <!-- More properties you want set on ActiveMQConnectionFactory --> </springs:bean> <!-- 创建队列工厂 --> <jms:activemq-connector name="jmsConnector" specification="1.1" brokerURL="vm://localhost" connectionFactory-ref="activeMqConnectionFactory"/> <!-- 获取控制台对象 --> <stdio:connector name="stdioConnector" messageDelayTime="1234" promptMessage="Please enter something: " /> <!-- 服务端从控制台获取信息发送至队列 --> <model name="jmsServer"> <service name="jmsService"> <inbound> <stdio:inbound-endpoint system="IN"/> </inbound> <outbound> <pass-through-router> <jms:outbound-endpoint connector-ref="jmsConnector" topic="backup-reports"/> </pass-through-router> </outbound> </service> </model> <!-- 客户端从队列获取信息发送控制台 --> <model name="jmsClient"> <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>
?
?
?
测试代码:
import org.mule.api.MuleContext;import org.mule.api.context.MuleContextFactory;import org.mule.config.spring.SpringXmlConfigurationBuilder;import org.mule.context.DefaultMuleContextFactory;/** * <p> * 简单需求: * 1.服务端从控制台接收信息转为消息发送之队列. * 2.客户端从队列获取消息转换为消息输出到控制台. * <p> * * 创建日期 2013-8-17<br> * @author $Author$<br> * @version $Revision$ $Date$ * @since 3.0.0 */public class MuleActiveMQMain { public static void main(String[] args) { try { String configFile = "mule-activemq-config-service.xml"; String[] configFileArr = new String[] {configFile }; MuleContextFactory muleContextFactory = new DefaultMuleContextFactory(); MuleContext context = muleContextFactory .createMuleContext(new SpringXmlConfigurationBuilder(configFileArr)); context.start(); } catch (Exception e) { e.printStackTrace(); } }}
?