I have below code in main method. I am not getting how i can check the acknowledgment sent from message broker . Basically i want to get the value of acknowledgment sent from message broker at line 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();
}
As i created Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
message broker will send the acknowledgement once it receives the message, but how producer will get it?
There is no visible acknowledgement sent from Broker to producer. In the non-TX case the send method will only return once the broker has ack'd it unless you configure the client to always send async or you send a non-persistent message. In the TX case the messages are always sent async unless you configure the always sync send option. The sync point in the TX case is the commit call which will not return until the messages have been persisted and the TX ends.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.