[英]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.