【发布时间】:2014-04-12 00:27:40
【问题描述】:
我在 main 方法中有以下代码。我不知道如何检查从消息代理发送的确认。基本上我想在第 1 行获取消息代理发送的确认值
try {
ActiveMQConnectionFactory connectionFactory =
new ActiveMQConnectionFactory(url);
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
Session session = connection.createSession(true,
Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createQueue(subject);
// Create a MessageProducer from the Session to the Topic or Queue
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
// Create a messages
String text = "Hello world! From Jon";
TextMessage message = session.createTextMessage(text);
producer.send(message);
// how to check acknowledgement here? // line1
session.commit();
// Clean up
session.close();
connection.close();
}
catch (Exception e) {
System.out.println("Caught: " + e);
e.printStackTrace();
}
正如我创建Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
消息代理收到消息后会发送确认,但生产者如何获得呢?
【问题讨论】:
-
the acknowledgement是什么意思?你的意思是发送成功还是来自消息处理器的某种类型的响应? -
@Martin 更新了我的帖子以澄清它