本文整理汇总了Java中javax.jms.Message.acknowledge方法的典型用法代码示例。如果您正苦于以下问题:Java Message.acknowledge方法的具体用法?Java Message.acknowledge怎么用?Java Message.acknowledge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jms.Message
的用法示例。
在下文中一共展示了Message.acknowledge方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMessage
import javax.jms.Message; //导入方法依赖的package包/类
@Override
public void onMessage(Message message) {
try {
if (message != null) {
logger.info("Message received " + message.getJMSMessageID());
boolean removeMessageFromQueue = messageHandler.handleMessage(message);
//Acknowledging the message with remove it from the queue
if(removeMessageFromQueue) {
logger.info("Acknowledged message (removing from queue): " + message.getJMSMessageID());
message.acknowledge();
} else {
logger.info("Leaving message " + message.getJMSMessageID() + " on the queue");
}
} else {
logger.info("Null message received");
}
} catch (Exception e) {
logger.error("Error while recieving message", e);
}
}
示例2: onMessage
import javax.jms.Message; //导入方法依赖的package包/类
/**
* takes the jms message
*/
public void onMessage(Message msg) {
try {
if (msg instanceof ObjectMessage) {
BasicEvent event = (BasicEvent)((ObjectMessage)msg).getObject();
if (logger.isDebugEnabled() || cisToLog.contains(event.getCiId())) {
logger.info(gson.toJson(event));
}
sensorHeartBeat.timeStampIt(event.getChannel());
sensorHeartBeat.timeStampIt(BasicEvent.DEFAULT_CHANNEL);
sensor.sendCEPEvent(event);
}
msg.acknowledge();
} catch (JMSException e) {
logger.info("caught Exception in onMessage",e);
}
}
示例3: doCleanupQueue
import javax.jms.Message; //导入方法依赖的package包/类
private void doCleanupQueue( final Session session, final Destination destination ) throws JMSException {
try {
MessageConsumer consumer = session.createConsumer(destination);
Message message = null;
do {
message = consumer.receiveNoWait();
if (message != null) {
message.acknowledge();
}
} while (message != null);
} finally {
releaseSession(false);
}
}
示例4: onMessage
import javax.jms.Message; //导入方法依赖的package包/类
/**
* (non-Javadoc)
*
* @see javax.jms.MessageListener#onMessage(javax.jms.Message)
*/
public void onMessage(Message msg) {
msgs.mark();
Context tc = msgTime.time();
try {
NotificationMessage notify = null;
if (msg instanceof TextMessage) {
try {
notify = parseMsg((TextMessage) msg);
} catch (JsonParseException e) {
logger.error("Got the bad message, not a valid json format - \n"
+ ((TextMessage) msg).getText() + "\n" + e.getMessage());
msg.acknowledge();
}
} else if (msg instanceof ObjectMessage) {
notify = (NotificationMessage) ((ObjectMessage) msg).getObject();
}
if (notify != null) {
logger.debug("Notification message received: " + notify.getText());
if (notify.getTimestamp() == 0) {
notify.setTimestamp(System.currentTimeMillis());
}
dispatcher.dispatch(notify);
}
msg.acknowledge();
} catch (Exception ex) {
logger.error("Can't process the notification message.", ex);
} finally {
tc.stop();
}
}
示例5: processMessage
import javax.jms.Message; //导入方法依赖的package包/类
private void processMessage(Message message) throws Throwable {
if (null == message) {
// log.error("message is null...");
return;
}
try {
XCO xcoMessage = null;
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text = textMessage.getText();
xcoMessage = XCO.fromXML(text);
} else {
// TODO
}
log.info("received a message from " + typeStr + "[" + queue.getName() + "]: " + xcoMessage);
boolean execResult = true;
if (null != xcoMessage) {
execResult = exec(service, xcoMessage, binding);
}
if (execResult && Session.SESSION_TRANSACTED == session.getAcknowledgeMode()) {
session.commit();
} else if (execResult && Session.CLIENT_ACKNOWLEDGE == session.getAcknowledgeMode()) {
message.acknowledge();
}
if (!execResult && Session.SESSION_TRANSACTED == session.getAcknowledgeMode()) {
session.rollback();
}
} catch (Throwable e) {
if (Session.SESSION_TRANSACTED == session.getAcknowledgeMode()) {
session.rollback();
}
throw e;
}
}
示例6: testConsumerWithBasicReject
import javax.jms.Message; //导入方法依赖的package包/类
@Parameters({ "broker-port", "admin-username", "admin-password", "broker-hostname" })
@Test
public void testConsumerWithBasicReject(String port,
String adminUsername,
String adminPassword,
String brokerHostname) throws Exception {
System.setProperty("AndesAckWaitTimeOut", "5000");
String queueName = "testConsumerWithBasicReject";
InitialContext initialContextForQueue = ClientHelper
.getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
.withQueue(queueName)
.build();
ConnectionFactory connectionFactory
= (ConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
Connection connection = connectionFactory.createConnection();
connection.start();
// publish message
Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = producerSession.createQueue(queueName);
MessageProducer producer = producerSession.createProducer(queue);
producer.send(producerSession.createTextMessage("Test message for reject test"));
producerSession.close();
// Consume published messages
Session subscriberSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
Destination subscriberDestination = (Destination) initialContextForQueue.lookup(queueName);
MessageConsumer consumer = subscriberSession.createConsumer(subscriberDestination);
Message message = consumer.receive(5000);
Assert.assertNotNull(message, "Message was not received");
message = consumer.receive(10000);
Assert.assertNotNull(message, "Requeued Message was not received");
Assert.assertTrue(message.getJMSRedelivered(), "Redelivered flag was not set");
message.acknowledge();
connection.close();
}
示例7: testConsumerWithBasicRecover
import javax.jms.Message; //导入方法依赖的package包/类
@Parameters({ "broker-port", "admin-username", "admin-password", "broker-hostname" })
@Test
public void testConsumerWithBasicRecover(String port,
String adminUsername,
String adminPassword,
String brokerHostname) throws Exception {
String queueName = "testConsumerWithBasicRecover";
InitialContext initialContextForQueue = ClientHelper
.getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
.withQueue(queueName)
.build();
ConnectionFactory connectionFactory
= (ConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
Connection connection = connectionFactory.createConnection();
connection.start();
// publish message
Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = producerSession.createQueue(queueName);
MessageProducer producer = producerSession.createProducer(queue);
TextMessage firstMessage = producerSession.createTextMessage("First message for reject test");
TextMessage secondMessage = producerSession.createTextMessage("Second message for reject test");
String correlationIdOne = "1";
String correlationIdTwo = "2";
firstMessage.setJMSCorrelationID(correlationIdOne);
secondMessage.setJMSCorrelationID(correlationIdTwo);
producer.send(firstMessage);
producer.send(secondMessage);
producerSession.close();
// Consume published messages
Session subscriberSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
Destination subscriberDestination = (Destination) initialContextForQueue.lookup(queueName);
MessageConsumer consumer = subscriberSession.createConsumer(subscriberDestination);
Message message = consumer.receive(5000);
Assert.assertNotNull(message, "Message was not received");
subscriberSession.recover();
// Message order can change after recovering
for (int i = 0; i < 2; i++) {
message = consumer.receive(5000);
Assert.assertNotNull(message, "Requeued message was not received");
if (correlationIdOne.equals(message.getJMSCorrelationID())) {
Assert.assertTrue(message.getJMSRedelivered(), "Redelivered flag was set in second message" + message);
} else {
Assert.assertFalse(message.getJMSRedelivered(), "Redelivered flag was set in first message");
}
message.acknowledge();
}
connection.close();
}