activemq jms 学习

来源:互联网 发布:pano2vr.js 域名限制 编辑:程序博客网 时间:2024/06/13 18:36
http://app.yinxiang.com/l/AAooDt8M8g5HpLUhnJmmaou6R6mq3Y8ARS0/
1.名词解释
JAVA JMS


2.activemq 消息 3种形式  JMS公共,点对点域,发布/订阅域

(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 方法。


3.下载链接 http://archive.apache.org/dist/activemq/apache-activemq/5.1.0/apache-activemq-5.1.0-bin.zip

解压,点击


即可启动, 默认的用户名密码是admin/admin。
默认后台访问地址

  1. http://localhost:8161/admin/index.jsp
可以观察队列与主动添加队列

4.activemq 接受和发消息基本流程

发送消息的基本步骤:
(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.maven 配置相关
<!-- activemq 相关maven依赖 -->

        <dependency>

            <groupId>javax.jms</groupId>

            <artifactId>jms</artifactId>

            <version>1.1</version>

        </dependency>

        <dependency>

            <groupId>org.apache.activemq</groupId>

            <artifactId>activemq-core</artifactId>

            <version>5.5.0</version>

        </dependency>

        <dependency>

            <groupId>org.apache.activemq</groupId>

            <artifactId>activemq-pool</artifactId>

            <version>5.7.0</version>
        </dependency>

三个是activemq相关的maven依赖(注意版本号)



注:web项目 需要注入jmsTemplate


6.代码参考  1.activemq 点对点demo
                2.activemq 发布者/订阅  springmvc  maven 例子[代码参考]


参考链接 :
     http://blog.sina.com.cn/s/blog_616e189f0100nuyn.html
     http://boy00fly.iteye.com/blog/1103586
     http://blog.csdn.net/jwdstef/article/details/17380471
     http://www.cnblogs.com/wintersun/p/3962302.html
0 0
原创粉丝点击