jms中消息接收的实现原理
来源:互联网 发布:淘宝的孕妇装 编辑:程序博客网 时间:2024/06/05 07:56
在jms中有多处同步异步的概念,使用消息驱动bean实现消息异步消费的含义是消息从broker端传送至consumer的客户端时,不管consumer是否调用onmessage来处理消息,会持续的向unconsumermessage容器总发送消息
消息驱动Bean
驱动Bean (MDB) 提供了一个实现异步通信比直接使用Java消息服务(JMS)更容易地方法。创建MDB接收异步JMS消息。容器处理为JMS队列和主题所要求加载处理的大部分工作。它向相关的MDB发送所有的消息。一个MDB允许J2EE应用发送异步消息,该应用能处理这些消息。实现javax.jms.MessageListener接口和使用@MessageDriven注释该Bean来指定一个Bean是消息驱动Bean。消息驱动Bean实例
- import javax.ejb.MessageDriven;
- import javax.ejb.ActivationConfigProperty;
- import javax.ejb.Inject;
- import javax.jms.*;
- import java.util.*;
- import javax.ejb.TimedObject;
- import javax.ejb.Timer;
- import javax.ejb.TimerService;
- @MessageDriven(
- activationConfig = {
- @ActivationConfigProperty(propertyName="connectionFactoryJndiName",
- propertyValue="jms/TopicConnectionFactory"),
- @ActivationConfigProperty(propertyName="destinationName",
- propertyValue="jms/myTopic"),
- @ActivationConfigProperty(propertyName="destinationType",
- propertyValue="javax.jms.Topic"),
- @ActivationConfigProperty(propertyName="messageSelector",
- propertyValue="RECIPIENT = 'MDB'")
- }
- )
- /**
- *监听可配置JMS队列或者主题和通过当一个消息发送到队列或者主题
- *调用它的onMessage()方法得到提醒的一个简单的消息驱动
- *该Bean打印消息的内容
- */
- public class MessageLogger implements MessageListener, TimedObject
- {
- @Inject javax.ejb.MessageDrivenContext mc;
- public void onMessage(Message message)
- {
- System.out.println("onMessage() - " + message);
- try
- {
- String subject = message.getStringProperty("subject");
- String inmessage = message.getStringProperty("message");
- System.out.println("Message received\n\tDate: " + new java.util.Date() +
- "\n\tSubject: " + subject + "\n\tMessage: " + inmessage + "\n");
- System.out.println("Creating Timer a single event timer");
- TimerService ts = mc.getTimerService();
- Timer timer = ts.createTimer(30000, subject);
- System.out.println("Timer created by MDB at: " +
- new Date(System.currentTimeMillis()) +" with info: "+subject);
- }
- catch (Throwable ex)
- {
- ex.printStackTrace();
- }
- }
- public void ejbTimeout(Timer timer)
- {
- System.out.println("EJB 3.0: Timer with MDB");
- System.out.println("ejbTimeout() called at: " +
- new Date(System.currentTimeMillis()));
- return;
- }
- }
0 0
- jms中消息接收的实现原理
- java 实现jms的客户端(发送接收消息)
- java 实现jms的客户端(发送接收消息)
- Spring+JMS实现消息的发送与接收
- python实现jms客户端(发送接收消息)
- JMS五种消息的发送/接收的例子
- JMS五种消息的发送/接收的例子
- JMS五种消息的发送/接收的例子
- JMS五种消息的发送/接收的例子
- 实现工具栏中添加的组合框接收回车消息
- JMS的5中消息类型
- JMS中点对点消息
- 配置WAS中的JMS接收MQ消息
- ActiveMQ-JMS(三):接收消息
- JMS的消息模式
- spring的jms:用spring的JmsTemplate发送和接收消息
- JMS P2P方式的消息发送/接收的一个简单例子
- spring的jms:用spring的JmsTemplate发送和接收消息 .
- Android自定义控件<二>
- Runtime全方位装逼指南
- 如何解决wampsever 中mysql无法显示中文的问题
- 380. Insert Delete GetRandom O(1)
- git学习(2) 远程连接github
- jms中消息接收的实现原理
- 私人整理mysql笔记
- ES6/ES2015核心内容
- linux 手动源码安装lnmp(亲测)
- TaintDroid部署过程详解
- VS编译器中加入QT库
- 【DVB】【法国】法国NRJ进行超高清/HDR数字地面电视测试
- poj Pots(BFS)(路径记录)(模拟)
- 眼图——概念与测量(摘记)