![](/img/trans.png)
[英]how to get acknowledgement from Kafka broker if message is produced by producer?
[英]How producer can access the acknowledgement sent by message broker?
我在主要方法中有以下代码。 我不知道如何检查消息代理发送的确认。 基本上我想从第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);
消息代理在收到消息后将发送确认,但是生产者将如何获得它?
没有从经纪人发送到生产者的可见确认。 在非TX的情况下,除非代理将客户端配置为始终发送异步消息或发送非持久消息,否则send方法仅在代理确认后才返回。 在TX情况下,除非始终配置“始终同步发送”选项,否则消息总是异步发送。 在TX情况下,同步点是commit调用,直到消息被持久保存并且TX结束后才返回。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.