任何人都可以知道在JMS中进行客户端确认。
现在我正在使用AUTO_ACKNOWLEDGEMENT
作为确认目的。
我知道如何将AUTO_ACKNOWLEDGEMENT
更改为CLIENT_ACKNOWLEDGEMENT
这是我的代码。
public Connection openConnection() throws JMSException {
ConnectionFactory connectionFactory = jmsConfiguration
.connectionFactory();
Connection conn = connectionFactory.createConnection();
return conn;
}
/**
*
* @param queueData
* @param queueName
* @throws JMSException
* @throws DataCaptureException
*/
public void sendMessage(String queueData, String queueName)
throws JMSException, DataCaptureException {
Connection connection = null;
try {
connection = openConnection();
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(queueName);
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message message = session.createTextMessage(queueData);
producer.send(message);
session.close();
} catch (JMSException e) {
throw new DataCaptureException(e.getMessage(), e.getCause());
} finally {
if (connection != null) {
connection.close();
}
}
}
/**
*
* @param queueName
* @return
* @throws JMSException
* @throws DataCaptureException
*/
public String receiveMessage(String queueName) throws JMSException,
DataCaptureException {
Connection connection = null;
String queueMessage = null;
try {
connection = openConnection();
connection.start();
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session
.createQueue(queueName));
Message message = consumer.receive(1000);
consumer.close();
if (null != message) {
queueMessage = ((TextMessage) message).getText();
}
session.close();
} catch (JMSException e) {
throw new DataCaptureException(e.getMessage(), e.getCause());
} finally {
if (connection != null) {
connection.close();
}
}
return queueMessage;
}
任何人都可以告诉我如何将其更改为CLIENT_ACKNOWLEDGEMENT
以及如何验证它。
答案 0 :(得分:1)
您需要将Session的创建更改为CLIENT_ACKNOWLEDGE:
Session session = connection.createSession(false,
Session.CLIENT_ACKNOWLEDGE);
然后你必须在代码中自己确认这些消息:
message.acknowledge();
如果您对删除该邮件感到满意,则应该确认该邮件。验证它的工作原理是查看目标上是否仍然存在该消息。