- 浏览: 2828340 次
- 性别:
- 来自: 武汉
文章分类
- 全部博客 (1173)
- 名言警句 (5)
- 心情随笔 (50)
- 数据库 (57)
- Java基础 (241)
- J2EE框架 (91)
- 数据结构 (12)
- 程序设计 (21)
- WEB技术 (128)
- 网络日志 (12)
- IT资讯 (247)
- linux (64)
- solaris (2)
- 其它 (143)
- WebService (4)
- 日语学习 (2)
- 机器人 (5)
- Android (5)
- cgywin (3)
- Game (1)
- DWR (1)
- spring (8)
- canvas (1)
- Guava (3)
- Modbus (5)
- 测试 (6)
- mongodb (9)
- Quartz (2)
- Cron (1)
- windows (2)
- 持续集成 (1)
- bootstrap (3)
- 结对编程 (1)
- nodejs (1)
- Netty (1)
- 安全 (3)
- webstorm (2)
- sparkline (1)
- Job (1)
- git (3)
- Maven (3)
- knockout (5)
- jquery (1)
- bower (1)
- docker (1)
- confluence (4)
- wiki (1)
- GoogleMap (1)
- jekyll (10)
- ruby (2)
- npm (3)
- browserify (1)
- gulp (3)
- openwrt (1)
- discuz (3)
- 输入法 (1)
- JPA (1)
- eclipse (2)
- IntelliJ (1)
- css (1)
- 虚拟机 (1)
- 操作系统 (1)
- azkaban (2)
- scrum (1)
最新评论
-
pangxiea_:
你好, 想请问一下 Linux下 这么使用rxtxcomm 在 ...
使用Java进行串口通信 -
abababudei:
请教一下,这个您是怎么解决的:/dev/ttyS2enteri ...
Java应用程序的MODBUS通讯 -
xuniverse:
hannibal005 写道楼主,我问下 request.se ...
用javascript与java进行RSA加密与解密 -
atxkm:
找了一下午,终于找到了
gulp 拷贝文件时如何移除文件目录结构 -
kalogen:
gtczr 写道非常感谢,经过我自己的修改,已经完美实现。发出 ...
用javascript与java进行RSA加密与解密
有二种方式可以测试。
1. 透过testng, 在测试类中完成的jms服务器的启动与关闭。
a.初始化jms服务器
@BeforeClass(groups = "jms") public void setupActiveMQ() throws Exception { BrokerService broker = new BrokerService(); broker.setPersistent(false); broker.setUseJmx(false); broker.start(); URI uri = broker.getVmConnectorURI(); ConnectionFactory factory = new ActiveMQConnectionFactory(uri); //String uri = "vm://localhost?broker.persistent=false"; //ConnectionFactory factory = new ActiveMQConnectionFactory(uri); Connection connection = factory.createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); destination = session.createQueue("TestQueue@router1"); }
b. 运行测试类
@Test(groups = "jms") public void sendMessage() throws JMSException { TextMessage msg = session.createTextMessage(); msg.setText("hello"); session.createProducer(destination).send(msg); }
c. 验证接收到的消息
@Test(groups = "jms", dependsOnMethods = "sendMessage", timeOut = 1000) public void receiveMessage() throws JMSException { MessageConsumer consumer = session.createConsumer(destination); TextMessage msg = (TextMessage) consumer.receive(); assert "hello".equals(msg.getText()); }
2. 透过maven-activemq-plugin插件,运行jms服务器,然后分别实现发送与接收
a. maven 配置
<plugin> <groupId>org.apache.activemq.tooling</groupId> <artifactId>maven-activemq-plugin</artifactId> <version>5.2.0</version> <configuration> <configUri> xbean:file:src/main/resources/net/sunbeta/jms/activemq.xml </configUri> <fork>false</fork> <systemProperties> <property> <name>javax.net.ssl.keyStorePassword</name> <value>password</value> </property> <property> <name>org.apache.activemq.default.directory.prefix</name> <value>./target/</value> </property> </systemProperties> </configuration> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.5.6</version> </dependency> <dependency> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-xbean</artifactId> <version>6.1.11</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-activemq</artifactId> <version>1.1.0</version> </dependency> </dependencies> </plugin>
其中 activemq.xml 的配置为:
<?xml version="1.0"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="./data"> <!-- The transport connectors ActiveMQ will listen to --> <transportConnectors> <transportConnector name="openwire" uri="tcp://localhost:61616"/> </transportConnectors> </broker> </beans>
b.消息发送
public class JmsProducer { private ConnectionFactory factory; private Connection connection; private Session session; private MessageProducer producer; public JmsProducer(ConnectionFactory factory, String queueName) throws JMSException { this.factory = factory; connection = factory.createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue(queueName); producer = session.createProducer(destination); } public void run() throws JMSException { for (int i = 0; i < 100; i++) { System.out.println("Creating Message " + i); Message message = session.createTextMessage("Hello World!"); producer.send(message); } } public void close() throws JMSException { if (connection != null) { connection.close(); } } }
创建一个broker去调用它
public class JmsBroker { public static String brokerURL = "tcp://localhost:61616"; // mvn clean compile exec:java // -Dexec.mainClass=net.sunbeta.test.jms.JmsBroker public static void main(String[] args) throws Exception { // setup the connection to ActiveMQ ConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL); JmsProducer producer = new JmsProducer(factory, "test"); producer.run(); producer.close(); } }
c. 消息接收
public class JmsConsumer implements MessageListener{ public static String brokerURL = "tcp://localhost:61616"; private ConnectionFactory factory; private Connection connection; private Session session; private MessageConsumer consumer; public static void main(String[] args) { JmsConsumer app = new JmsConsumer(); app.run(); } public void run() { try { ConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL); connection = factory.createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue("test"); consumer = session.createConsumer(destination); consumer.setMessageListener(this); } catch (Exception e) { System.out.println("Caught:" + e); e.printStackTrace(); } } public void onMessage(Message message) { try { if (message instanceof TextMessage) { TextMessage txtMessage = (TextMessage) message; System.out.println("Message received: " + txtMessage.getText()); } else { System.out.println("Invalid message received."); } } catch (JMSException e) { System.out.println("Caught:" + e); e.printStackTrace(); } }
OK !
发表评论
-
spring mvc @controller unit test
2013-11-20 14:14 38451. spring mvc controller imple ... -
Tomcat 生产服务器性能优化
2013-07-23 06:45 976试想以下这个情景:你已经开发好了一个程序,这个程序的排版很不 ... -
Loading Multiple Spring Application Contexts with their own ClassLoader
2013-07-11 20:45 1036package de.incompleteco.spring ... -
Maven系列2--pom.xml 配置详解
2011-01-06 18:00 3143<project xmlns="http ... -
fisheye2.3.6 安装笔记
2010-09-16 20:25 2202一. 准备工作 1. 下载fisheye ... -
服务器端编程的十大性能问题
2010-09-15 12:01 1211今年5 月底,瑞士计算 ... -
JMX in spring 配置
2010-09-07 12:00 3018JConsole中的连接:简单的localhost:1099 ... -
Ehcache 2.0:后写式缓存和JTA支持
2010-05-22 11:13 1815开源缓存框架Ehcache 最 ... -
Twitter系统运维经验
2010-04-12 22:24 1514最近看到的另外一个 ... -
采用OSGi框架开发项目的十个问题
2010-03-21 18:08 1427近期,InfoQ针对Java模块 ... -
IBM和Eclipse加大对OSGi的支持
2010-03-21 18:05 1231为Java提供模块性的OSGi,正在受到IBM和Eclipse ... -
Castor功能与应用参考
2010-03-12 12:48 35731. 项目简介Castor是一个开源的Java项目 ... -
hibernate之 DetachedCriteria实现多表查询
2009-07-25 17:13 13059DetachedCriteria detachedCriter ... -
spring AOP 理论知识点总结
2009-07-24 17:47 21351.1 AOP 的概念 ... -
web.xml 中的listener、 filter、servlet 加载顺序及其详解
2009-07-02 16:14 4081在项目中总会遇到一些 ... -
maven笔记
2009-06-22 22:14 1492mvn package : 项目打包 mvn help:ef ... -
利用maven构建多模块项目
2009-06-17 14:28 53301. 先单独构建各模块为一个独立的项目。 jar项目: m ... -
Maven基础
2009-06-17 12:58 1823下载Maven安装文件。 定义环境变量M2_HOME到pat ... -
安装M2eclipse步骤
2009-06-15 14:45 37781.下载下列所需文件 eclipse3.4.2 ... -
用 Maven 做项目管理
2009-06-08 18:01 2600在Java 世界中我们很多的开发人员选择用Ant 来构 ...
相关推荐
Jmeter压力测试 ActiveMQ性能 JMS性能测试
sprin jms activemq 测试 两个 一个是jndi 一个是activemq
activeMQ是jms的一种,是java是实现两个系统之间交互的方式,MQ分为队列模式和订阅模式,对这两种模式分别进行了测试通过。
jms测试程序,将tomcat和activeMq整合在一起做的一个发送接受的发布订阅的例子
activemq集成spring,和原生的active测试active的p2p和pub/sub方式
java JMS模拟ActiveMQ代理服务器并实现消息收发,这里是工程源码,已经过测试,可以直接使用。
SpringMvc+redis+activeMq实现消息发布订阅(测试通过) redis和activeMq jms各自需要的Jar包在其它资源中上传,大家可以下载。 这个例子拿到项目中可直接用
本章我将通过spring jms和activemq实现单Web项目服务器间异步访问和多Web项目服务器间异步访问。 一. 简介 1. 什么是Apache ActiveMq Apache ActiveMq是最流行和最强大的开源消息和集成服务器。同时Apache ActiveMq...
ActiveMQ测试用例依赖的jar包,activemq-all-5.15.2.jar 和 jms-1.1.jar
ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,尽管JMS规范出台已经是很久的事情了,但是JMS在当今的J2EE应用中间仍然扮演着特殊的地位. ⒈ 多种语言和协议编写客户端。语言: Java,C,C++,C#,...
ActiveMQ默认使用的TCP连接端口是61616, 通过查看该端口的信息可以测试ActiveMQ是否成功启动 netstat -an|find "61616" C:\Documents and Settings\Administrator>netstat -an|find "61616" TCP 0.0.0.0:61616 0.0....
一、JMS基本概念 二、activemq介绍及安装 1、消息中间件简介 2、activemq 2.1、activemq简介 2.2、activemq下载 2.3、运行activemq服务 2.4、测试 2.5、监控 3、activemq特性 4、activemq使用场景 三、...
ActiveMQ 是Apache出品,最流行的,能力...可以用作内存JMS提供程序,非常适合单元测试JMS 支持可插拔传输协议,例如in-VM,TCP,SSL,NIO,UDP,多播,JGroups和JXTA传输 使用JDBC和高性能日志支持非常快速的持久性
JMS、ActiveMQ入门及深入使用的例子,这些例子都是我测试的
spring集成activeMQ框架 配置方式(内含三种常见的消息接受监听方式的配置)JMS 配置测试等等
包括:通过源码安装、基本的配置示例、启动、测试运行、关闭等 n 三:理解和掌握JMS 包括:基本概念、消息结构、可靠性机制、PTP、Pub/Sub、API结构、JMS应用开 发的基本步骤、持久和非持久的Topic等 n 四:用...
1、解压安装文件,执行\apache-activemq-5.13.3-bin\apache-activemq-5.13.3\bin\win64\wrapper.exe. 2、测试发送消息,打开本地服务器地址http://localhost:8161,登录服务器,默认用户名密码:admin,admin。登录...
虽然ActiveMQ目前已经不是开发时的主要消息中间件, 但是对于简单使用JMS的场景而言, ActiveMQ仍然是一个比较成熟、稳定的框架,可以供初学者、小微企业快速上手。 虽然Apache ActiveMQ目前有多种安装方式, 使用...
该项目是一个Eclipse插件,可帮助配置和管理ActiveMQ JMS Messaging Broker,以在受控环境中测试部署模型。 还提供编辑器来配置控制ActiveMQ的文档。
——学习参考资料:仅用于个人学习使用! 本代码仅作学习交流,切勿用于商业用途,否则后果自负。若涉及侵权,请联系,会尽快处理! 未进行详尽测试,请自行调试!