简单需求:
1.服务端从控制台接收信息转为消息发送之队列.
2.客户端从队列获取消息转换为消息输出到控制台.
mule配置信息如下:
1. <springs:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
2. <springs:property name="locations">
3. <springs:list>
4. <springs:value>classpath:mq.properties</springs:value>
5. <springs:value>classpath:broker.properties</springs:value>
6. </springs:list>
7. </springs:property>
8. <springs:property name="fileEncoding">
9. <springs:value>UTF-8</springs:value>
10. </springs:property>
11. </springs:bean>
12.
13.
14.
15.
16.
17. <springs:bean id="activeMqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
18. <springs:property name="brokerURL" value="${broker.tcp.local.url}"/>
19. <!-- More properties you want set on ActiveMQConnectionFactory -->
20. </springs:bean>
21.
22. <!-- 创建队列工厂 -->
23. <jms:activemq-connector name="jmsConnector" specification="1.1" brokerURL="vm://localhost" connectionFactory-ref="activeMqConnectionFactory"/>
24.
25. <!-- 获取控制台对象 -->
26. <stdio:connector name="stdioConnector"
27. messageDelayTime="1234"
28. promptMessage="Please enter something: "
29. />
30.
31. <!-- 服务端从控制台获取信息发送至队列 -->
32. <model name="jmsServer">
33. <service name="jmsService">
34. <inbound>
35. <stdio:inbound-endpoint system="IN"/>
36. </inbound>
37. <outbound>
38. <pass-through-router>
39. <jms:outbound-endpoint connector-ref="jmsConnector" topic="backup-reports"/>
40. </pass-through-router>
41. </outbound>
42. </service>
43. </model>
44. <!-- 客户端从队列获取信息发送控制台 -->
45. <model name="jmsClient">
46. <service name="Backup Reporting Service">
47. <inbound>
48. <jms:inbound-endpoint topic="backup-reports" connector-ref="jmsConnector">
49. <jms:jmsmessage-to-object-transformer/>
50. </jms:inbound-endpoint>
51. </inbound>
52. <outbound>
53. <pass-through-router>
54. <stdio:outbound-endpoint system="OUT"/>
55. </pass-through-router>
56. </outbound>
57. </service>
58. </model>
测试代码:
1. import org.mule.api.MuleContext;
2. import org.mule.api.context.MuleContextFactory;
3. import org.mule.config.spring.SpringXmlConfigurationBuilder;
4. import org.mule.context.DefaultMuleContextFactory;
5.
6. /**
7. * <p>
8. * 简单需求:
9. * 1.服务端从控制台接收信息转为消息发送之队列.
10. * 2.客户端从队列获取消息转换为消息输出到控制台.
11. * <p>
12. *
13. * 创建日期 2013-8-17<br>
14. * @author $Author$<br>
15. * @version $Revision$ $Date$
16. * @since 3.0.0
17. */
18. public class MuleActiveMQMain {
19. public static void main(String[] args) {
20. try {
21. String configFile = "mule-activemq-config-service.xml";
22. String[] configFileArr = new String[] {configFile };
23. MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
24. MuleContext context = muleContextFactory
25. .createMuleContext(new SpringXmlConfigurationBuilder(configFileArr));
26. context.start();
27. } catch (Exception e) {
28. e.printStackTrace();
29. }
30.
31. }
32. }