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();