`
xkorey
  • 浏览: 152672 次
  • 性别: Icon_minigender_1
  • 来自: 石家庄
社区版块
存档分类
最新评论

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链接:
http://xkorey.iteye.com/blog/2113910

应该还会有后续……
分享到:
评论

相关推荐

    ActiveMQ+Camel+Spring+jms Demo(一)

    **ActiveMQ+Camel+Spring+jms Demo(一)** 在IT行业中,集成不同组件以构建高效、可扩展的消息传递系统是一项常见的任务。本示例将深入探讨如何使用ActiveMQ作为消息中间件,Apache Camel作为集成工具,以及Spring...

    Spring+JMS+ActiveMQ+Tomcat实现消息服务的demo

    基于Spring+JMS+ActiveMQ+Tomcat,我使用的版本情况如下所示:Spring 3.2.0,ActiveMQ 5.4.3,Tomcat 6.0.43。本例通过详细的说明和注释,实现消息服务的基本功能:发送与接收。Spring对JMS提供了很好的支持,可以...

    activeMQ+spring整合

    综上所述,"activeMQ+spring整合"是一个实用的示例,它演示了如何在Spring环境中配置和使用ActiveMQ,以实现消息的可靠传输。通过下载并研究`activemqDOME`这个压缩包中的代码,你可以更深入地理解这个整合过程,...

    基于Spring+JMS+ActiveMQ+Tomcat的整合ActiveMQSpringDemo实例源码.zip

    基于Spring+JMS+ActiveMQ+Tomcat的整合ActiveMQSpringDemo实例源码,此实例基于Spring+JMS+ActiveMQ+Tomcat,注解的完整实例,包含jar包,可供学习及设计参考。

    Spring+JMS+ActiveMQ+Tomcat jar下载

    在"Spring+JMS+ActiveMQ+Tomcat"的组合中,Spring作为核心框架负责应用的结构和依赖管理,而JMS提供消息传递机制。ActiveMQ作为JMS的实现,承担起消息队列的职责,确保消息的可靠传输。Tomcat则作为运行环境,承载着...

    activemq +jms(原生和集成spring-jms)

    在"activemq + jms(原生和集成spring-jms)"的主题中,我们将探讨如何使用ActiveMQ原生API以及结合Spring-JMS框架来实现消息队列的创建与使用,主要涵盖以下几个核心知识点: 1. **ActiveMQ的基本概念**:包括Broker...

    基于Spring+JMS+ActiveMQ+Tomcat整合

    基于Spring+JMS+ActiveMQ+Tomcat,做一个Spring4.1.0和ActiveMQ5.11.1整合实例,实现了Point-To-Point的异步队列消息和PUB/SUB(发布/订阅)模型,简单实例,不包含任何业务。

    P2P网络借贷平台项目SSH+Redis+ActiveMQ+POI+Shiro+AngularJS+Nginx+Quartz等

    3、该项目采用了struts2 hibernate spring和 spring data jpa 开源框架完成,并融入了cxf开源webservice框架的应用,而这些技术都是当下流行的技术。 4、在缓存方面运用了互联网的流行技术redis实现缓存存贮,...

    SpringBoot+ActiveMq+MQTT实现消息的发送和接收

    这通常包括`spring-boot-starter-activemq`和`org.apache.activemq:activemq-client`,以及可能的MQTT客户端库,如`org.eclipse.paho:org.eclipse.paho.client.mqttv3`。 2. 配置ActiveMQ:在`application....

    activemq+spring demo 简单示例222

    本文将以“activemq+spring demo”为例,深入探讨如何将Apache ActiveMQ与Spring框架进行整合,并通过一个简单的示例来展示其实现过程。 首先,我们需要了解ActiveMQ。ActiveMQ是Apache软件基金会开发的一个开放源...

    ActiveMQ+Spring+Maven Demo

    使用spring jmstemplate写的activemq小demo,浅显易懂。工程下载导入可用(maven 工程) activemq 可直接apache官网下载 传送门http://activemq.apache.org/download.html

    JMS+ActiveMQ+Spring 完整样例代码

    **JMS+ActiveMQ+Spring 完整样例代码详解** 在Java世界中,消息队列(Message Queue,简称MQ)是一种重要的中间件技术,它允许应用程序之间通过异步通信来解耦系统组件。Java消息服务(Java Message Service,简称...

    SpringBoot整合ActiveMQ+websocket.docx

    在Spring Boot应用中整合ActiveMQ和WebSocket,可以创建一个实时通信系统,使后端服务能够高效地推送消息到前端客户端。以下将详细解释这个过程的关键知识点: 1. **ActiveMQ**:Apache ActiveMQ是一个开源的消息...

    activemq+spring demo 简单示例

    本`activemq+spring demo`简单示例旨在帮助开发者理解如何在`Spring`环境中集成和使用`ActiveMQ`。通过这个示例,我们可以学习到以下关键知识点: 1. **ActiveMQ的基本概念**:`ActiveMQ`作为消息中间件,负责在...

    jms+activeMq+spring学习简单例子

    标题“jms+activeMq+spring学习简单例子”表明这个压缩包包含了一些示例代码,用于演示如何在Spring框架中集成JMS和ActiveMQ,以便于理解和学习。通过这个例子,开发者可以了解如何在实际应用中实现基于消息的通信。...

    Spring + ActiveMq + maven demo

    **二、Spring与ActiveMQ的集成** 1. **创建Maven项目** 在IDE中新建一个Maven项目,添加Spring和ActiveMQ相关的依赖。在`pom.xml`文件中,你需要包含以下依赖: ```xml &lt;groupId&gt;org.springframework ...

Global site tag (gtag.js) - Google Analytics