ActiveMQ+Camel+Spring+jms Demo(二)

client端请求服务端消息,服务端将数字消息 number*2 返回。文本消息 添加 client+text 返回。


具体修改。

route类。
client端修改为:
from("jms:queue:client:numbers").to("multiplier");
from("jms:queue:client:strings").to("textplier");


server端修改为:
from("jms:queue:server:numbers").to("multiplier");
from("jms:queue:server:strings").to("textplier");


service对应的也要修改:
client service 修改为向server端发送消息:

   public int sendHelloWorldNumToCamel(){
ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);
int response = (Integer)camelTemplate.sendBody("jms:queue:server:numbers", ExchangePattern.InOut, 22);
return response;
}

public String sendHelloWorldTextToCamel(String text){
ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);
String response = (String)camelTemplate.sendBody("jms:queue:server:strings", ExchangePattern.InOut, text);
return response;
}


对应的server的service修改为:

public int sendHelloWorldNumToCamel(){
ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);
int response = (Integer)camelTemplate.sendBody("jms:queue:client:numbers", ExchangePattern.InOut, 22);
return response;
}

public String sendHelloWorldTextToCamel(String text){
ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);
String response = (String)camelTemplate.sendBody("jms:queue:client:strings", ExchangePattern.InOut, text);
return response;
}


添加了一个新的xml。camel-client.xml:

<camel:camelContext id="camel-client">
<camel:template id="camelTemplate"/>
</camel:camelContext>

<context:property-placeholder location="classpath:camel.properties"
ignore-resource-not-found="true"/>

<bean id="client-jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://${host}:${tcp.port}"/>
</bean>


camel.properties 的配置:
client端host应写为server的ip,server端host是client的ip。

# properties for the application
tcp.port=61610
host=server
#host=xkorey-pc


web.xml中添加

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:camel-server.xml,
classpath:camel-client.xml,
classpath:spring-base.xml
</param-value>
</context-param>



另外2个官方demo链接:
[url]http://xkorey.iteye.com/blog/2113910[/url]

应该还会有后续……
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值