ActiveMQ消费指定消息

接收的时候指定MessageID

ActiveMQConnection connection = (ActiveMQConnection) new ActiveMQConnectionFactory().createConnection();

Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

//P_1为消息ID

MessageConsumer myConsumer = session.createConsumer(session.createTopic("TestMessage"), "P_1");

myConsumer.setMessageListener(new MessageListener() {

@Override

publicvoid onMessage(Message msg) {

try {

System.out.println("Message ID:"+ msg.getJMSMessageID());

} catch (JMSException e) {

e.printStackTrace(); } } });

myConsumer.close();

session.close();

connection.stop();

connection.close();

 

转自http://my.oschina.net/csen66/blog/89799

posted @ 2013-01-25 10:09  悟寰轩-叶秋  阅读(1027)  评论(0编辑  收藏  举报