Apache ActiveMQ教程(二)
来源:互联网 发布:淘宝jbl官方旗舰店 编辑:程序博客网 时间:2024/06/01 09:01
五、Point-to-Point (点对点)消息模式开发流程
1、生产者(producer)开发流程(ProducerTool.java):
1.1 创建Connection:
根据url,user和password创建一个jms Connection。
1.2 创建Session:
在connection的基础上创建一个session,同时设置是否支持事务和ACKNOWLEDGE标识。
1.3 创建Destination对象:
需指定其对应的主题(subject)名称,producer和consumer将根据subject来发送/接收对应的消息。
1.4 创建MessageProducer:
根据Destination创建MessageProducer对象,同时设置其持久模式。
1.5 发送消息到队列(Queue):
封装TextMessage消息,使用MessageProducer的send方法将消息发送出去。
2、消费者(consumer)开发流程(ConsumerTool.java):
2.1 实现MessageListener接口:
消费者类必须实现MessageListener接口,然后在onMessage()方法中监听消息的到达并处理。
2.2 创建Connection:
根据url,user和password创建一个jms Connection,如果是durable模式,还需要给connection设置一个clientId。
2.3 创建Session和Destination:
与ProducerTool.java中的流程类似,不再赘述。
2.4创建replyProducer【可选】:
可以用来将消息处理结果发送给producer。
2.5 创建MessageConsumer:
根据Destination创建MessageConsumer对象。
2.6 消费message:
在onMessage()方法中接收producer发送过来的消息进行处理,并可以通过replyProducer反馈信息给producer
if (message.getJMSReplyTo() !=null) {
replyProducer.send(message.getJMSReplyTo(),
session.createTextMessage("Reply: " + message.getJMSMessageID()));
}
- Apache ActiveMQ教程(二)
- Apache ActiveMQ教程(二)
- Apache ActiveMQ教程二 (消息主题订阅)
- ActiveMQ教程(二)
- Apache ActiveMQ教程(一)
- Apache ActiveMQ教程(三)
- Apache ActiveMQ教程(四)
- Apache ActiveMQ教程(五)
- Apache ActiveMQ教程(一)
- Apache ActiveMQ教程(三)
- Apache ActiveMQ教程(四)
- Apache ActiveMQ教程(五)
- Apache ActiveMQ教程(一)
- ActiveMQ教程(二)-安全策略
- ActiveMQ教程(二)- 集群
- Apache ActiveMQ教程
- Apache ActiveMQ教程(一)
- apache-activemq(二)
- Struts2原理
- Dialog使用详解——开源项目Standup Timer学习总结(三)
- chrome 相关网址汇总
- Apache ActiveMQ教程(一)
- Android----http请求工具类
- Apache ActiveMQ教程(二)
- pb12.5 数据库char类型字段后面跟空格问题
- 假期归来 契机
- Apache ActiveMQ教程(三)
- 动态改变NSLevelIndicatorCell的值
- 模板的小用法<一>
- JAVA 基本数据类型长度
- CSS布局口诀珍藏版
- POSTFIX的基本配置与管理