1、 概述與介紹html
ActiveMQ 是Apache出品,最流行的、功能強大的即時通信和集成模式的開源服務器。ActiveMQ 是一個徹底支持JMS1.1和J2EE 1.4規範的 JMS Provider實現。提供客戶端支持跨語言和協議,帶有易於在充分支持JMS 1.1和1.4使用J2EE企業集成模式和許多先進的功能。java
2、 特性linux
一、 多種語言和協議編寫客戶端。語言: Java、C、C++、C#、Ruby、Perl、Python、PHP。應用協議:OpenWire、Stomp REST、WS Notification、XMPP、AMQPweb
二、徹底支持JMS1.1和J2EE 1.4規範 (持久化,XA消息,事務)spring
三、對Spring的支持,ActiveMQ能夠很容易內嵌到使用Spring的系統裏面去,並且也支持Spring2.0的特性apache
四、經過了常見J2EE服務器(如 Geronimo、JBoss 四、GlassFish、WebLogic)的測試,其中經過JCA 1.5 resource adaptors的配置,可讓ActiveMQ能夠自動的部署到任何兼容J2EE 1.4 商業服務器上windows
五、支持多種傳送協議:in-VM、TCP、SSL、NIO、UDP、JGroups、JXTA服務器
六、支持經過JDBC和journal提供高速的消息持久化網絡
七、從設計上保證了高性能的集羣,客戶端-服務器,點對點session
八、支持Ajax
九、支持與Axis的整合
十、能夠很容易得調用內嵌JMS provider,進行測試
3、 安裝
開發環境:
System:Windows
JDK:1.6+
IDE:eclipse
apache ActiveMQ 5.8
一、 下載ActiveMQ,下載地址:http://www.apache.org/dyn/closer.cgi?path=/activemq/apache-activemq/5.8.0/apache-activemq-5.8.0-bin.zip
二、 解壓apache-activemq-5.8.0.zip便可完成ActiveMQ的安裝
三、 解壓後目錄結構以下
+bin (windows下面的bat和unix/linux下面的sh) 啓動ActiveMQ的啓動服務就在這裏
+conf (activeMQ配置目錄,包含最基本的activeMQ配置文件)
+data (默認是空的)
+docs (index,replease版本里面沒有文檔)
+example (幾個例子)
+lib (activeMQ使用到的lib)
+webapps (系統管理員控制檯代碼)
+webapps-demo(系統示例代碼)
-activemq-all-5.8.0.jar (ActiveMQ的binary)
-user-guide.html (部署指引)
-LICENSE.txt
-NOTICE.txt
-README.txt
其餘文件就不相信介紹了,搞Java的應該都知道幹什麼用的。
你能夠進入bin目錄,使用activemq.bat雙擊啓動(windows用戶能夠選擇系統位數,若是你是linux的話,就用命令行的發送去啓動 ./activemq start),若是一切順利,你就會看見相似下面的信息:
若是你看到這個,那麼恭喜你成功了。若是你啓動看到了異常信息:
Caused by: java.io.IOException: Failed to bind to server socket: tcp://0.0.0.0:61616?maximumConnections=1000&wireformat.maxFrameSize=104857600 due to: java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind
那麼我告訴你,很不幸,你的端口被佔用了。接下來你大概想知道是哪一個程序佔用了你的端口,並kill掉該進程或服務。或者你要嘗試修改ActiveMQ的默認端口61616(ActiveMQ使用的默認端口是61616),在大多數狀況下,佔用61616端口的是Internet Connection Sharing (ICS) 這個Windows服務,你只需中止它就能夠啓動ActiveMQ了。
四、 啓動成功就能夠訪問管理員界面:http://localhost:8161/admin,默認用戶名和密碼admin/admin。若是你想修改用戶名和密碼的話,在conf/jetty-realm.properties中修改便可。
其中在導航菜單中,Queues是隊列方式消息。Topics是主題方式消息。Subscribers消息訂閱監控查詢。Connections能夠查看連接數,分別能夠查看xmpp、ssl、stomp、openwire、ws和網絡連接。Network是網絡連接數監控。Send能夠發送消息數據。
五、 運行demo示例,在dos控制檯輸入activemq.bat xbean:../conf/activemq-demo.xml 便可啓動demo示例。官方提供的user-guide.html中的access the web console中是提示輸入:activemq.bat console xbean:conf/activemq-demo.xml,我用這種方式不成功。
固然你還能夠用絕對的文件目錄方式:activemq.bat xbean:file:D:/mq/conf/activemq-demo.xml
若是提示conf/activemq-demo.xml沒有找到,你能夠嘗試改變下路徑,也就是去掉上面的「..」。經過http://localhost:8161/demo/ 就能夠訪問示例了。
4、 消息示例
JMS 公共
點對點域
發佈/訂閱域
ConnectionFactory
QueueConnectionFactory
TopicConnectionFactory
Connection
QueueConnection
TopicConnection
Destination
Queue
Topic
Session
QueueSession
TopicSession
MessageProducer
QueueSender
TopicPublisher
MessageConsumer
QueueReceiver
TopicSubscriber
(1)、點對點方式(point-to-point)
點對點的消息發送方式主要創建在 Message Queue,Sender,reciever上,Message Queue 存貯消息,Sneder 發送消息,receive接收消息.具體點就是Sender Client發送Message Queue ,而 receiver Cliernt從Queue中接收消息和"發送消息已接受"到Quere,確認消息接收。消息發送客戶端與接收客戶端沒有時間上的依賴,發送客戶端能夠在任什麼時候刻發送信息到Queue,而不須要知道接收客戶端是否是在運行
(2)、發佈/訂閱 方式(publish/subscriber Messaging)
發佈/訂閱方式用於多接收客戶端的方式.做爲發佈訂閱的方式,可能存在多個接收客戶端,而且接收端客戶端與發送客戶端存在時間上的依賴。一個接收端只能接收他建立之後發送客戶端發送的信息。做爲subscriber ,在接收消息時有兩種方法,destination的receive方法,和實現message listener 接口的onMessage 方法。
二、ActiviteMQ接收和發送消息基本流程
發送消息的基本步驟:
(1)、建立鏈接使用的工廠類JMS ConnectionFactory
(2)、使用管理對象JMS ConnectionFactory創建鏈接Connection,並啓動
(3)、使用鏈接Connection 創建會話Session
(4)、使用會話Session和管理對象Destination建立消息生產者MessageSender
(5)、使用消息生產者MessageSender發送消息
消息接收者從JMS接受消息的步驟
(1)、建立鏈接使用的工廠類JMS ConnectionFactory
(2)、使用管理對象JMS ConnectionFactory創建鏈接Connection,並啓動
(3)、使用鏈接Connection 創建會話Session
(4)、使用會話Session和管理對象Destination建立消息接收者MessageReceiver
(5)、使用消息接收者MessageReceiver接受消息,須要用setMessageListener將MessageListener接口綁定到MessageReceiver消息接收者必須實現了MessageListener接口,須要定義onMessage事件方法。
5、 代碼示例
在代碼開始,咱們先建一個project,在這個project中添加以下jar包
添加完jar包後就能夠開始實際的代碼工做了。
一、 使用JMS方式發送接收消息
消息發送者
package com.hoo.mq.jms;import javax.jms.Connection;import javax.jms.ConnectionFactory;import javax.jms.DeliveryMode;import javax.jms.Destination;import javax.jms.MessageProducer;import javax.jms.Session;import javax.jms.TextMessage;import org.apache.activemq.ActiveMQConnection;import org.apache.activemq.ActiveMQConnectionFactory;/*** <b>function:</b> 消息發送者* @author hoojo* @createDate 2013-6-19 上午11:26:43* @file MessageSender.java* @package com.hoo.mq.jms* @project ActiveMQ-5.8* @blog http://blog.csdn.net/IBM_hoojo* @email hoojo_@126.com* @version 1.0*/public class MessageSender {// 發送次數public static final int SEND_NUM = 5;// tcp 地址public static final String BROKER_URL = "tcp://localhost:61616";// 目標,在ActiveMQ管理員控制檯建立 http://localhost:8161/admin/queues.jsppublic static final String DESTINATION = "hoo.mq.queue";/*** <b>function:</b> 發送消息* @author hoojo* @createDate 2013-6-19 下午12:05:42* @param session* @param producer* @throws Exception*/public static void sendMessage(Session session, MessageProducer producer) throws Exception {for (int i = 0; i < SEND_NUM; i++) {String message = "發送消息第" + (i + 1) + "條";TextMessage text = session.createTextMessage(message);System.out.println(message);producer.send(text);}}public static void run() throws Exception {Connection connection = null;Session session = null;try {// 建立連接工廠ConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, BROKER_URL);// 經過工廠建立一個鏈接connection = factory.createConnection();// 啓動鏈接connection.start();// 建立一個session會話session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);// 建立一個消息隊列Destination destination = session.createQueue(DESTINATION);// 建立消息製做者MessageProducer producer = session.createProducer(destination);// 設置持久化模式producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);sendMessage(session, producer);// 提交會話session.commit();} catch (Exception e) {throw e;} finally {// 關閉釋放資源if (session != null) {session.close();}if (connection != null) {connection.close();}}}public static void main(String[] args) throws Exception {MessageSender.run();}}
接受者
package com.hoo.mq.jms;import javax.jms.Connection;import javax.jms.ConnectionFactory;import javax.jms.Destination;import javax.jms.Message;import javax.jms.MessageConsumer;import javax.jms.Session;import javax.jms.TextMessage;import org.apache.activemq.ActiveMQConnection;import org.apache.activemq.ActiveMQConnectionFactory;/*** <b>function:</b> 消息接收者* @author hoojo* @createDate 2013-6-19 下午01:34:27* @file MessageReceiver.java* @package com.hoo.mq.jms* @project ActiveMQ-5.8* @blog http://blog.csdn.net/IBM_hoojo* @email hoojo_@126.com* @version 1.0*/public class MessageReceiver {// tcp 地址public static final String BROKER_URL = "tcp://localhost:61616";// 目標,在ActiveMQ管理員控制檯建立 http://localhost:8161/admin/queues.jsppublic static final String DESTINATION = "hoo.mq.queue";public static void run() throws Exception {Connection connection = null;Session session = null;try {// 建立連接工廠ConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, BROKER_URL);// 經過工廠建立一個鏈接connection = factory.createConnection();// 啓動鏈接connection.start();// 建立一個session會話session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);// 建立一個消息隊列Destination destination = session.createQueue(DESTINATION);// 建立消息製做者MessageConsumer consumer = session.createConsumer(destination);while (true) {// 接收數據的時間(等待) 100 msMessage message = consumer.receive(1000 * 100);TextMessage text = (TextMessage) message;if (text != null) {System.out.println("接收:" + text.getText());} else {break;}}// 提交會話session.commit();} catch (Exception e) {throw e;} finally {// 關閉釋放資源if (session != null) {session.close();}if (connection != null) {connection.close();}}}public static void main(String[] args) throws Exception {MessageReceiver.run();}}
二、 Queue隊列方式發送點對點消息數據
發送方
package com.hoo.mq.queue;import javax.jms.DeliveryMode;import javax.jms.MapMessage;import javax.jms.Queue;import javax.jms.QueueConnection;import javax.jms.QueueConnectionFactory;import javax.jms.QueueSession;import javax.jms.Session;import org.apache.activemq.ActiveMQConnection;import org.apache.activemq.ActiveMQConnectionFactory;/*** <b>function:</b> Queue 方式消息發送者* @author hoojo* @createDate 2013-6-19 下午04:34:36* @file QueueSender.java* @package com.hoo.mq.queue* @project ActiveMQ-5.8* @blog http://blog.csdn.net/IBM_hoojo* @email hoojo_@126.com* @version 1.0*/public class QueueSender {// 發送次數public static final int SEND_NUM = 5;// tcp 地址public static final String BROKER_URL = "tcp://localhost:61616";// 目標,在ActiveMQ管理員控制檯建立 http://localhost:8161/admin/queues.jsppublic static final String DESTINATION = "hoo.mq.queue";/*** <b>function:</b> 發送消息* @author hoojo* @createDate 2013-6-19 下午12:05:42* @param session* @param sender* @throws Exception*/public static void sendMessage(QueueSession session, javax.jms.QueueSender sender) throws Exception {for (int i = 0; i < SEND_NUM; i++) {String message = "發送消息第" + (i + 1) + "條";MapMessage map = session.createMapMessage();map.setString("text", message);map.setLong("time", System.currentTimeMillis());System.out.println(map);sender.send(map);}}public static void run() throws Exception {QueueConnection connection = null;QueueSession session = null;try {// 建立連接工廠QueueConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, BROKER_URL);// 經過工廠建立一個鏈接connection = factory.createQueueConnection();// 啓動鏈接connection.start();// 建立一個session會話session = connection.createQueueSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);// 建立一個消息隊列Queue queue = session.createQueue(DESTINATION);// 建立消息發送者javax.jms.QueueSender sender = session.createSender(queue);// 設置持久化模式sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);sendMessage(session, sender);// 提交會話session.commit();} catch (Exception e) {throw e;} finally {// 關閉釋放資源if (session != null) {session.close();}if (connection != null) {connection.close();}}}public static void main(String[] args) throws Exception {QueueSender.run();}}
接收方
package com.hoo.mq.queue;import javax.jms.JMSException;import javax.jms.MapMessage;import javax.jms.Message;import javax.jms.MessageListener;import javax.jms.Queue;import javax.jms.QueueConnection;import javax.jms.QueueConnectionFactory;import javax.jms.QueueSession;import javax.jms.Session;import org.apache.activemq.ActiveMQConnection;import org.apache.activemq.ActiveMQConnectionFactory;/*** <b>function:</b> 消息接收者; 依賴hawtbuf-1.9.jar* @author hoojo* @createDate 2013-6-19 下午01:34:27* @file MessageReceiver.java* @package com.hoo.mq.queue* @project ActiveMQ-5.8* @blog http://blog.csdn.net/IBM_hoojo* @email hoojo_@126.com* @version 1.0*/public class QueueReceiver {// tcp 地址public static final String BROKER_URL = "tcp://localhost:61616";// 目標,在ActiveMQ管理員控制檯建立 http://localhost:8161/admin/queues.jsppublic static final String TARGET = "hoo.mq.queue";public static void run() throws Exception {QueueConnection connection = null;QueueSession session = null;try {// 建立連接工廠QueueConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, BROKER_URL);// 經過工廠建立一個鏈接connection = factory.createQueueConnection();// 啓動鏈接connection.start();// 建立一個session會話session = connection.createQueueSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);// 建立一個消息隊列Queue queue = session.createQueue(TARGET);// 建立消息製做者javax.jms.QueueReceiver receiver = session.createReceiver(queue);receiver.setMessageListener(new MessageListener() {public void onMessage(Message msg) {if (msg != null) {MapMessage map = (MapMessage) msg;try {System.out.println(map.getLong("time") + "接收#" + map.getString("text"));} catch (JMSException e) {e.printStackTrace();}}}});// 休眠100ms再關閉Thread.sleep(1000 * 100);// 提交會話session.commit();} catch (Exception e) {throw e;} finally {// 關閉釋放資源if (session != null) {session.close();}if (connection != null) {connection.close();}}}public static void main(String[] args) throws Exception {QueueReceiver.run();}}
三、 Topic主題發佈和訂閱消息
消息發送方
package com.hoo.mq.topic;import javax.jms.DeliveryMode;import javax.jms.MapMessage;import javax.jms.Session;import javax.jms.Topic;import javax.jms.TopicConnection;import javax.jms.TopicConnectionFactory;import javax.jms.TopicPublisher;import javax.jms.TopicSession;import org.apache.activemq.ActiveMQConnection;import org.apache.activemq.ActiveMQConnectionFactory;/*** <b>function:</b> Queue 方式消息發送者* @author hoojo* @createDate 2013-6-19 下午04:34:36* @file QueueSender.java* @package com.hoo.mq.topic* @project ActiveMQ-5.8* @blog http://blog.csdn.net/IBM_hoojo* @email hoojo_@126.com* @version 1.0*/public class TopicSender {// 發送次數public static final int SEND_NUM = 5;// tcp 地址public static final String BROKER_URL = "tcp://localhost:61616";// 目標,在ActiveMQ管理員控制檯建立 http://localhost:8161/admin/queues.jsppublic static final String DESTINATION = "hoo.mq.topic";/*** <b>function:</b> 發送消息* @author hoojo* @createDate 2013-6-19 下午12:05:42* @param session 會話* @param publisher 發佈者* @throws Exception*/public static void sendMessage(TopicSession session, TopicPublisher publisher) throws Exception {for (int i = 0; i < SEND_NUM; i++) {String message = "發送消息第" + (i + 1) + "條";MapMessage map = session.createMapMessage();map.setString("text", message);map.setLong("time", System.currentTimeMillis());System.out.println(map);publisher.send(map);}}public static void run() throws Exception {TopicConnection connection = null;TopicSession session = null;try {// 建立連接工廠TopicConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, BROKER_URL);// 經過工廠建立一個鏈接connection = factory.createTopicConnection();// 啓動鏈接connection.start();// 建立一個session會話session = connection.createTopicSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);// 建立一個消息隊列Topic topic = session.createTopic(DESTINATION);// 建立消息發送者TopicPublisher publisher = session.createPublisher(topic);// 設置持久化模式publisher.setDeliveryMode(DeliveryMode.NON_PERSISTENT);sendMessage(session, publisher);// 提交會話session.commit();} catch (Exception e) {throw e;} finally {// 關閉釋放資源if (session != null) {session.close();}if (connection != null) {connection.close();}}}public static void main(String[] args) throws Exception {TopicSender.run();}}
接收方
package com.hoo.mq.topic;import javax.jms.JMSException;import javax.jms.MapMessage;import javax.jms.Message;import javax.jms.MessageListener;import javax.jms.Session;import javax.jms.Topic;import javax.jms.TopicConnection;import javax.jms.TopicConnectionFactory;import javax.jms.TopicSession;import javax.jms.TopicSubscriber;import org.apache.activemq.ActiveMQConnection;import org.apache.activemq.ActiveMQConnectionFactory;/*** <b>function:</b> 消息接收者; 依賴hawtbuf-1.9.jar* @author hoojo* @createDate 2013-6-19 下午01:34:27* @file MessageReceiver.java* @package com.hoo.mq.topic* @project ActiveMQ-5.8* @blog http://blog.csdn.net/IBM_hoojo* @email hoojo_@126.com* @version 1.0*/public class TopicReceiver {// tcp 地址public static final String BROKER_URL = "tcp://localhost:61616";// 目標,在ActiveMQ管理員控制檯建立 http://localhost:8161/admin/queues.jsppublic static final String TARGET = "hoo.mq.topic";public static void run() throws Exception {TopicConnection connection = null;TopicSession session = null;try {// 建立連接工廠TopicConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, BROKER_URL);// 經過工廠建立一個鏈接connection = factory.createTopicConnection();// 啓動鏈接connection.start();// 建立一個session會話session = connection.createTopicSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);// 建立一個消息隊列Topic topic = session.createTopic(TARGET);// 建立消息製做者TopicSubscriber subscriber = session.createSubscriber(topic);subscriber.setMessageListener(new MessageListener() {public void onMessage(Message msg) {if (msg != null) {MapMessage map = (MapMessage) msg;try {System.out.println(map.getLong("time") + "接收#" + map.getString("text"));} catch (JMSException e) {e.printStackTrace();}}}});// 休眠100ms再關閉Thread.sleep(1000 * 100);// 提交會話session.commit();} catch (Exception e) {throw e;} finally {// 關閉釋放資源if (session != null) {session.close();}if (connection != null) {connection.close();}}}public static void main(String[] args) throws Exception {TopicReceiver.run();}}
四、 整合Spring實現消息發送和接收,在整合以前咱們須要添加jar包,須要的jar包以下
這些jar包能夠在D:\apache-activemq-5.8.0\lib這個lib目錄中找到,添加完jar包後就開始編碼工做。
消息發送者
package com.hoo.mq.spring.support;import java.util.Date;import javax.jms.JMSException;import javax.jms.MapMessage;import javax.jms.Message;import javax.jms.Session;import org.springframework.context.ApplicationContext;import org.springframework.context.support.FileSystemXmlApplicationContext;import org.springframework.jms.core.JmsTemplate;import org.springframework.jms.core.MessageCreator;/*** <b>function:</b> Spring JMSTemplate 消息發送者* @author hoojo* @createDate 2013-6-24 下午02:18:48* @file Sender.java* @package com.hoo.mq.spring.support* @project ActiveMQ-5.8* @blog http://blog.csdn.net/IBM_hoojo* @email hoojo_@126.com* @version 1.0*/public class Sender {public static void main(String[] args) {ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath:applicationContext-*.xml");JmsTemplate jmsTemplate = (JmsTemplate) ctx.getBean("jmsTemplate");jmsTemplate.send(new MessageCreator() {public Message createMessage(Session session) throws JMSException {MapMessage message = session.createMapMessage();message.setString("message", "current system time: " + new Date().getTime());return message;}});}}
消息接收者
package com.hoo.mq.spring.support;import java.util.Map;import org.springframework.context.ApplicationContext;import org.springframework.context.support.FileSystemXmlApplicationContext;import org.springframework.jms.core.JmsTemplate;/*** <b>function:</b> Spring JMSTemplate 消息接收者* @author hoojo* @createDate 2013-6-24 下午02:22:32* @file Receiver.java* @package com.hoo.mq.spring.support* @project ActiveMQ-5.8* @blog http://blog.csdn.net/IBM_hoojo* @email hoojo_@126.com* @version 1.0*/public class Receiver {@SuppressWarnings("unchecked")public static void main(String[] args) {ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath:applicationContext-*.xml");JmsTemplate jmsTemplate = (JmsTemplate) ctx.getBean("jmsTemplate");while(true) {Map<String, Object> map = (Map<String, Object>) jmsTemplate.receiveAndConvert();System.out.println("收到消息:" + map.get("message"));}}}
這裏主要是用到了JmsTemplate這個消息模板,這個對象在spring的IoC容器中管理,因此要從spring的容器上下文中獲取。下面看看spring的配置文件applicationContext-beans.xml內容:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.1.xsd"><!-- 鏈接池 --><bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop"><property name="connectionFactory"><bean class="org.apache.activemq.ActiveMQConnectionFactory"><property name="brokerURL" value="tcp://localhost:61616" /></bean></property></bean><!-- 鏈接工廠 --><bean id="activeMQConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"><property name="brokerURL" value="tcp://localhost:61616" /></bean><!-- 配置消息目標 --><bean id="destination" class="org.apache.activemq.command.ActiveMQQueue"><!-- 目標,在ActiveMQ管理員控制檯建立 http://localhost:8161/admin/queues.jsp --><constructor-arg index="0" value="hoo.mq.queue" /></bean><!-- 消息模板 --><bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"><property name="connectionFactory" ref="activeMQConnectionFactory" /><property name="defaultDestination" ref="destination" /><property name="messageConverter"><bean class="org.springframework.jms.support.converter.SimpleMessageConverter" /></property></bean></beans>
這裏的整合就比較簡單了,若是你是web工程,那你在須要用jms的時候,只需用注入jmsTemplate便可。
原文地址:http://www.cnblogs.com/hoojo/p/active_mq_jms_apache_activeMQ.html
其餘相關:http://www.cnblogs.com/xwdreamer/archive/2012/02/21/2360818.html
http://www.cnblogs.com/diorlv/p/3328712.html