惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Help Net Security
Help Net Security
G
Google Developers Blog
雷峰网
雷峰网
WordPress大学
WordPress大学
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Engineering at Meta
Engineering at Meta
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
F
Full Disclosure
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
J
Java Code Geeks
U
Unit 42
C
Cyber Attacks, Cyber Crime and Cyber Security
V
V2EX
C
Cisco Blogs
博客园 - 司徒正美
Project Zero
Project Zero
L
LINUX DO - 热门话题
阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
Scott Helme
Scott Helme
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
S
Securelist
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyberwarzone
Cyberwarzone
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
T
Threatpost
Recorded Future
Recorded Future
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
The Register - Security
The Register - Security
S
Security Archives - TechRepublic
博客园 - Franky
N
News | PayPal Newsroom
Simon Willison's Weblog
Simon Willison's Weblog
S
SegmentFault 最新的问题
W
WeLiveSecurity
A
Arctic Wolf
B
Blog

博客园 - wolfman

正则表达式Pattern 字符串分割成一维数组、二维数组,一维数组与二维数组之间的转换 ActiveMQ在C#中的应用 深入掌握JMS(十二):MDB 深入掌握JMS(十一):TemporaryQueue和TemporaryTopic 深入掌握JMS(十):JMSCorrelationID与Selector 深入掌握JMS(九):Selector 深入掌握JMS(八):JMSReplyTo 深入掌握JMS(七):DeliveryMode例子 深入掌握JMS(六):消息头 深入掌握JMS(四):实战Queue 深入掌握JMS(五):实战Topic 深入掌握JMS(二):一个JMS例子 深入掌握JMS(一):JSM基础 oracle 分区表(转) Application,Session,Cookie,ViewState,Cache的区别(转) 网络编程基础 VS2008+Oracle92 网站发布注意问题 Windows Service开发应用
深入掌握JMS(三):MessageListener
wolfman · 2010-06-12 · via 博客园 - wolfman

消息的消费者接收消息可以采用两种方式:

              1、consumer.receive() 或 consumer.receive(int timeout);
              2、注册一个MessageListener。
            采用第一种方式,消息的接收者会一直等待下去,直到有消息到达,或者超时。后一种方式会注册一个监听器,当有消息到达的时候,会回调它的onMessage()方法。下面举例说明:
             MessageConsumer comsumer = session.createConsumer(queue);
             comsumer.setMessageListener(new MessageListener(){
                        @Override
                        public void onMessage(Message m) {
                            TextMessage textMsg = (TextMessage) m;
                            try {
                                System.out.println(textMsg.getText());
                            } catch (JMSException e) {
                                e.printStackTrace();
                            }
                        }
                    });