Java Messages Synchronous and Asynchronous
//The Consumer Class Consumes Messages in a Synchronous Manner public class Consumer {
public static void main(String[] args) {
try {
// Gets the JNDI context
Context jndiContext = new InitialContext();
// Looks up the administered objects
ConnectionFactory connectionFactory = (ConnectionFactory)
jndiContext.lookup("jms/javaee7/ConnectionFactory");
Destination queue = (Destination) jndiContext.lookup("jms/javaee7/Queue");
// Loops to receive the messages
try (JMSContext context = connectionFactory.createContext()) {
while (true) {
String message = context.createConsumer(queue).receiveBody(String.class);
}
}
} catch (NamingException e) {
e.printStackTrace();
}
}
}
//The Consumer Is a Message Listener public class Listener implements MessageListener {
public static void main(String[] args) {
try {
// Gets the JNDI context
Context jndiContext = new InitialContext();
// Looks up the administered objects
ConnectionFactory connectionFactory = (ConnectionFactory)
jndiContext.lookup("jms/javaee7/ConnectionFactory");
Destination queue = (Destination) jndiContext.lookup("jms/javaee7/Queue");
try (JMSContext context = connectionFactory.createContext()) {
context.createConsumer(queue).setMessageListener(new Listener());
}
} catch (NamingException e) {
e.printStackTrace();
}
}
public void onMessage(Message message) {
System.out.println("Async Message received: " + message.getBody(String.class));
}
}
Java Messages Synchronous and Asynchronous的更多相关文章
- Synchronous and Asynchronous I/O [Windows]
There are two types of input/output (I/O) synchronization: synchronous I/O and asynchronous I/O. Asy ...
- 操作系统OS - 阻塞(Blocking)非阻塞(Non-Blocking)与同步(Synchronous)异步(Asynchronous)
参考: http://blog.jobbole.com/103290/ https://www.zhihu.com/question/19732473/answer/23434554 http://b ...
- Should I expose asynchronous wrappers for synchronous methods?
Lately I've received several questions along the lines of the following, which I typically summarize ...
- Asynchronous Disk I/O Appears as Synchronous on Windows
Summary File I/O on Microsoft Windows can be synchronous or asynchronous. The default behavior for I ...
- Java资源大全中文版(Awesome最新版)
Awesome系列的Java资源整理.awesome-java 就是akullpp发起维护的Java资源列表,内容包括:构建工具.数据库.框架.模板.安全.代码分析.日志.第三方库.书籍.Java 站 ...
- Java开源框架推荐(全)
Build Tool Tools which handle the buildcycle of an application. Apache Maven - Declarative build and ...
- Java性能提示(全)
http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...
- 【Java】-NO.20.Exam.1.Java.1.001- 【1z0-807】- OCEA
1.0.0 Summary Tittle:[Java]-NO.20.Exam.1.Java.1.001-[1z0-807] Style:EBook Series:Java Since:2017-10- ...
- java设计模式大全 Design pattern samples in Java(最经典最全的资料)
java设计模式大全 Design pattern samples in Java(最经典最全的资料) 2015年06月19日 13:10:58 阅读数:11100 Design pattern sa ...
随机推荐
- finally 语句
package unit5; public class FinallyDemo { int no1,no2; public FinallyDemo(String[] args) { try{ no1= ...
- HyperLink控件
设置链接 NavigateUrl 填写链接 text 属性 为显示内容
- 8.Smack类库
1.登陆IM Connection.DEBUG_ENABLED = true;//首先激活调试模式 1.1建立连接 首先,在启动DSM Message时,客户端通过XMPPConnection与服务器 ...
- 如何找到所有HTML Select 标签的选中项?
$(‘[name=NameofSelectedTag]:selected’);
- 实践1-qq邮箱主页
纯html的网页 采用table分割板块进行布局 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...
- WPF之资源字典zz
最近在看wpf相关东西,虽然有过两年的wpf方面的开发经验,但是当时开发的时候,许多东西一知半解,至今都是模模糊糊,框架基本是别人搭建,自己也就照着模板写写,现在许多东西慢慢的理解了,回顾以前的若干记 ...
- MONO 安装 分析
你是安装在/etc下的吧? 5.2是没有serverbusy的提示的,那时,它就傻等,给人造成down的假像.而现在的版本,会提示的. 你升级时,upgrade后边加参数了吗? 加了 /etc/jw ...
- TYVJ P1062 合并傻子 Label:环状dp
背景 从前有一堆傻子,钟某人要合并他们~但是,合并傻子是要掉RP的...... 描述 在一个园形操场的四周站着N个傻子,现要将傻子有次序地合并成一堆.规定每次只能选相邻的2个傻子合并成新的一个傻子,并 ...
- JQuery获取和设置Select选项常用方法总结 (转)
1.获取select 选中的 text: $("#cusChildTypeId").find("option:selected").text(); $(&quo ...
- Odoo(OpenERP) 多个子类重载同一个父类方法的执行顺序及如何调用父类的父类方法
首先说下起因,在修改英国会计模块(没错,就是那个安格鲁撒克逊记账模式!)中不符合中国国情的部分供能时,碰到了一个棘手的问题,简单的说就是B类继承它的父类A并重载了A的方法M,同时C类也继承了A类也重载 ...