本文整理了Java中javax.jms.Message.acknowledge()
方法的一些代码示例,展示了Message.acknowledge()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.acknowledge()
方法的具体详情如下:
包路径:javax.jms.Message
类名称:Message
方法名:acknowledge
[英]Acknowledges all consumed messages of the session of this consumed message.
All consumed JMS messages support the acknowledge method for use when a client has specified that its JMS session's consumed messages are to be explicitly acknowledged. By invoking acknowledge on a consumed message, a client acknowledges all messages consumed by the session that the message was delivered to.
Calls to acknowledge are ignored for both transacted sessions and sessions specified to use implicit acknowledgement modes.
A client may individually acknowledge each message as it is consumed, or it may choose to acknowledge messages as an application-defined group (which is done by calling acknowledge on the last received message of the group, thereby acknowledging all messages consumed by the session.)
Messages that have been received but not acknowledged may be redelivered.
[中]确认此已用消息会话的所有已用消息。
当客户端指定显式确认其JMS会话的已使用消息时,所有已使用的JMS消息都支持acknowledge方法。通过对已使用的消息调用acknowledge,客户机确认消息传递到的会话所使用的所有消息。
对于事务处理会话和指定使用隐式确认模式的会话,对确认的调用都将被忽略。
客户端可以在消息被消费时单独确认每条消息,也可以选择将消息作为应用程序定义的组进行确认(这是通过对组的最后一条消息调用acknowledge来完成的,从而确认会话所消费的所有消息)
已收到但未确认的信息可能会被重新发送。
代码示例来源:origin: apache/storm
/**
* Ack the message.
*
* @param msg the message
* @throws JMSException the JMS exception in case of error
*/
protected void doAck(final Message msg) throws JMSException {
msg.acknowledge();
LOG.debug("JMS message acked");
}
代码示例来源:origin: apache/storm
@Override
protected void doAck(final Message msg) throws JMSException {
// if there are no more pending consumed messages
// and storm delivered ack for all
if (getPendingAcks().isEmpty()) {
msg.acknowledge();
LOG.debug("JMS message acked");
} else {
LOG.debug("Not acknowledging the JMS message "
+ "since there are pending messages in the session");
}
}
}
代码示例来源:origin: apache/nifi
private void acknowledge(final Message message, final Session session) throws JMSException {
if (message != null && session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE) {
message.acknowledge();
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Perform a commit or message acknowledgement, as appropriate.
* @param session the JMS Session to commit
* @param message the Message to acknowledge
* @throws javax.jms.JMSException in case of commit failure
*/
protected void commitIfNecessary(Session session, @Nullable Message message) throws JMSException {
// Commit session or acknowledge message.
if (session.getTransacted()) {
// Commit necessary - but avoid commit call within a JTA transaction.
if (isSessionLocallyTransacted(session)) {
// Transacted session created by this container -> commit.
JmsUtils.commitIfNecessary(session);
}
}
else if (message != null && isClientAcknowledge(session)) {
message.acknowledge();
}
}
代码示例来源:origin: wildfly/wildfly
@Override
public void acknowledge() {
checkSession();
if (closed)
throw new IllegalStateRuntimeException("Context is closed");
try {
if (lastMessagesWaitingAck != null) {
lastMessagesWaitingAck.acknowledge();
}
} catch (JMSException e) {
throw JmsExceptionUtils.convertToRuntimeException(e);
}
}
代码示例来源:origin: apache/storm
@Override
public void success(TransactionAttempt tx) {
@SuppressWarnings("unchecked")
List<Message> messages = (List<Message>) batchMessageMap.remove(tx.getTransactionId());
if (messages != null) {
if (!messages.isEmpty()) {
LOG.debug("Success for batch with transaction id " + tx.getTransactionId() + "/" + tx.getAttemptId() + " for " + name);
}
for (Message msg : messages) {
String messageId = "UnknownId";
try {
messageId = msg.getJMSMessageID();
msg.acknowledge();
LOG.trace("Acknowledged message " + messageId);
} catch (JMSException e) {
LOG.warn("Failed to acknowledge message " + messageId, e);
}
}
} else {
LOG.warn("No messages found in batch with transaction id " + tx.getTransactionId() + "/" + tx.getAttemptId());
}
}
代码示例来源:origin: apache/activemq
if (batchSize > 0 && received > 0 && received % batchSize == 0) {
LOG.info("Acknowledging last " + batchSize + " messages; messages so far = " + received);
msg.acknowledge();
代码示例来源:origin: spring-projects/spring-framework
message.acknowledge();
代码示例来源:origin: apache/activemq
/**
* spec section 3.6 acking a message with automation acks has no effect.
* @throws Exception
*/
public void testAckMessageInTx() throws Exception {
Message[] outbound = new Message[] {session.createTextMessage("First Message")};
// sends a message
beginTx();
producer.send(outbound[0]);
outbound[0].acknowledge();
commitTx();
outbound[0].acknowledge();
// receives the first message
beginTx();
ArrayList<Message> messages = new ArrayList<Message>();
LOG.info("About to consume message 1");
Message message = consumer.receive(1000);
messages.add(message);
LOG.info("Received: " + message);
// validates that the rollbacked was not consumed
commitTx();
Message inbound[] = new Message[messages.size()];
messages.toArray(inbound);
assertTextMessagesEqual("Message not delivered.", outbound, inbound);
}
代码示例来源:origin: apache/activemq
message.acknowledge();
} catch(Exception e) {
jmsConnector.handleConnectionFailure(getConnnectionForConsumer());
代码示例来源:origin: javahongxi/whatsmars
@Override
public void onMessage(Message message) {
TextMessage textMessage = (TextMessage)message;
try {
System.out.println(textMessage.getText());
//......
//执行成功后,确认消息
message.acknowledge();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: apache/nifi
if (clientAcknowledge && lastMessage != null) {
try {
lastMessage.acknowledge(); // acknowledge all received messages by acknowledging only the last.
} catch (final JMSException e) {
logger.error("Failed to acknowledge {} JMS Message(s). This may result in duplicate messages. Reason for failure: {}",
代码示例来源:origin: com.betfair.cougar/jms-transport
@Override
public void handleEventProcessingError(Message errorEvent, Throwable exception) {
LOGGER.error("An error occurred processing event: [" + errorEvent + "]", exception);
try {
errorEvent.acknowledge();
} catch (JMSException ex) {
LOGGER.error("An error occured acknowledging bad JMS message [" + errorEvent + "]", ex);
}
}
}
代码示例来源:origin: camelinaction/camelinaction2
@Override
public void onComplete(Exchange exchange) {
LOG.info("Using JMS client acknowledge to accept the JMS message consumed: {}", jms);
try {
jms.acknowledge();
} catch (JMSException e) {
LOG.warn("JMS client acknowledge failed due: " + e.getMessage(), e);
}
}
});
代码示例来源:origin: com.mockrunner/mockrunner-jdk1.4-j2ee1.3
protected void acknowledgeMessage(Message message, MockSession session) throws JMSException
{
if(session.isAutoAcknowledge())
{
message.acknowledge();
}
}
}
代码示例来源:origin: org.projectodd.wunderboss/wunderboss-messaging
@Override
public Object call() throws Exception {
JMSContext.this.latestMessage.jmsMessage().acknowledge();
return null;
}
});
代码示例来源:origin: apache/activemq-artemis
@Override
public void onMessage(Message message) {
try {
message.acknowledge();
done.countDown();
} catch (JMSException ex) {
LOG.info("Caught exception.", ex);
}
}
});
代码示例来源:origin: org.apache.tomee/openejb-core
@Override
public void acknowledge() {
session();
try {
if (lastMessagesWaitingAck != null) {
lastMessagesWaitingAck.acknowledge();
}
} catch (final JMSException e) {
throw toRuntimeException(e);
}
}
代码示例来源:origin: apache/activemq-artemis
/**
* Acknowledge
*
* @throws JMSException Thrown if an error occurs
*/
@Override
public void acknowledge() throws JMSException {
if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
ActiveMQRALogger.LOGGER.trace("acknowledge()");
}
session.getSession(); // Check for closed
message.acknowledge();
}
代码示例来源:origin: org.apache.apex/malhar-library
/**
* Commit/Acknowledge messages that have been received.<br/>
* @throws javax.jms.JMSException
*/
protected void acknowledge() throws JMSException
{
if (isTransacted()) {
getSession().commit();
} else if (getSessionAckMode(getAckMode()) == Session.CLIENT_ACKNOWLEDGE) {
lastMsg.acknowledge(); // acknowledge all consumed messages till now
}
}
内容来源于网络,如有侵权,请联系作者删除!