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

你可能感兴趣的:(ActiveMQ消费指定消息)