俗话说的好:温故而知新。这就是我发布到这里的原因。
ActiveMQ+Camel+Spring 简单整合
官网我就不列了,我做的这个demo只是跑通了而已,还有很多需要完善的地方。
待续……
欢迎拍砖
简单描述下我的这个demo:web界面有2个请求,一个是向mq发送数字消息,一个是文本消息。
并将响应的结果回显到web。
不完美的地方:没有用2台电脑来测试mq请求和应答。测了回补上,待续……
pom文件就不贴了。
就贴比较关键的配置,其实这些都是从官方example中抄过来的。
camel-server.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:broker="http://activemq.apache.org/schema/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<context:component-scan base-package="com.activeMqCamelSpring.demo"/>
<context:property-placeholder location="classpath:camel.properties"
ignore-resource-not-found="true"/>
<camel:camelContext id="camel-server">
<camel:package>com.activeMqCamelSpring.demo.server</camel:package>
<camel:jmxAgent id="agent" createConnector="true"/>
</camel:camelContext>
<camel:camelContext id="camel-client">
<camel:template id="camelTemplate"/>
</camel:camelContext>
<broker:broker useJmx="true" persistent="false" brokerName="myBroker">
<broker:transportConnectors>
<broker:transportConnector name="vm" uri="vm://myBroker"/>
<broker:transportConnector name="tcp" uri="tcp://localhost:${tcp.port}"/>
</broker:transportConnectors>
</broker:broker>
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="vm://myBroker"/>
</bean>
</beans>
camel.properties 就一句:
tcp.port=61610
web.xml中
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:camel-server.xml,
classpath:spring-base.xml
</param-value>
</context-param>
ServerRoutes中也很简单
public class ServerRoutes extends RouteBuilder {
@Override
public void configure() throws Exception {
from("jms:queue:numbers").to("multiplier");
from("jms:queue:strings").to("textplier");
}
}
multiplier 类
@Service(value = "multiplier")
public class Treble {
public int multiply(final int originalNumber) {
return originalNumber * 3;
}
}
textplier类
@Service(value = "textplier")
public class TextPlier {
public String say(final String text){
return "activeMQ with camel for :"+text;
}
}
还有一个service
@Service
public class CamleService {
@Autowired
AbstractApplicationContext context;
public int sendHelloWorldNumToCamel(){
ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);
int response = (Integer)camelTemplate.sendBody("jms:queue: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:strings", ExchangePattern.InOut, text);
return response;
}
}
运行效果截图
附件是camel官方的example和我的demo打包
分享到:
相关推荐
NULL 博文链接:https://xkorey.iteye.com/blog/2114391
基于Spring+JMS+ActiveMQ+Tomcat,我使用的版本情况如下所示:Spring 3.2.0,ActiveMQ 5.4.3,Tomcat 6.0.43。本例通过详细的说明和注释,实现消息服务的基本功能:发送与接收。Spring对JMS提供了很好的支持,可以...
SpringBoot+ActiveMq+MQTT实现消息的发送和接收 后台消费者、生产者、消息发送接口、发送消息业务类等相关配置
Spring+JMS+ActiveMQ+Tomcat jar下载,在博客主页有实例,欢迎换看
activemq+spring demo 简单示例。安装activemq 启动,运行Test
SpringBoot整合ActiveMQ+websocket.docx ,该文档包含于activemq整合的各个情况,springboot,js,websocket与mq整合,该资源是上传代码的word文档部分
基于Spring+JMS+ActiveMQ+Tomcat,做一个Spring4.1.0和ActiveMQ5.11.1整合实例,实现了Point-To-Point的异步队列消息和PUB/SUB(发布/订阅)模型,简单实例,不包含任何业务。
activemq+spring demo 简单示例
activeMQ 和spring 整合 亲自测试过特别好的demo,推荐下载
ActiveMQ+SpringActiveMQ+SpringActiveMQ+SpringActiveMQ+Spring
activeMQ+spring+springmvc整合示例
3、该项目采用了struts2 hibernate spring和 spring data jpa 开源框架完成,并融入了cxf开源webservice框架的应用,而这些技术都是当下流行的技术。 4、在缓存方面运用了互联网的流行技术redis实现缓存存贮,...
使用spring jmstemplate写的activemq小demo,浅显易懂。工程下载导入可用(maven 工程) activemq 可直接apache官网下载 传送门http://activemq.apache.org/download.html
demo...springmvc+dubbo/zookeeper+activemq+redis+mybatis+druid
Windowss 下 Spring + ActiveMq + maven 集成配置分为两章,环境搭建之前参考了网上的博客以及同事的配置。
基于Spring+JMS+ActiveMQ+Tomcat,我使用的版本情况如下所示: •Spring 2.5 •ActiveMQ 5.4.0 •Tomcat 6.0.30 下面通过学习与配置,实现消息服务的基本功能:发送与接收。Spring对JMS提供了很好的支持,可以...