public void removeMessage(ConnectionContext context, final MessageAck ack) throws IOException { final boolean debug = LOG.isDebugEnabled(); JournalQueueAck remove = new JournalQueueAck(); remove.setDestination(destination); remove.setMessageAck(ack); final RecordLocation location = peristenceAdapter.writeCommand(remove, ack.isResponseRequired()); if (!context.isInTransaction()) { if (debug) { LOG.debug("Journalled message remove for: " + ack.getLastMessageId() + ", at: " + location); } removeMessage(ack, location); } else { if (debug) { LOG.debug( "Journalled transacted message remove for: " + ack.getLastMessageId() + ", at: " + location); } synchronized (this) { inFlightTxLocations.add(location); } transactionStore.removeMessage(this, ack, location); context .getTransaction() .addSynchronization( new Synchronization() { public void afterCommit() throws Exception { if (debug) { LOG.debug( "Transacted message remove commit for: " + ack.getLastMessageId() + ", at: " + location); } synchronized (JournalMessageStore.this) { inFlightTxLocations.remove(location); removeMessage(ack, location); } } public void afterRollback() throws Exception { if (debug) { LOG.debug( "Transacted message remove rollback for: " + ack.getLastMessageId() + ", at: " + location); } synchronized (JournalMessageStore.this) { inFlightTxLocations.remove(location); } } }); } }
public void replayRemoveMessage(ConnectionContext context, MessageAck messageAck) { try { // Only remove the message if it has not already been removed. Message t = longTermStore.getMessage(messageAck.getLastMessageId()); if (t != null) { longTermStore.removeMessage(context, messageAck); } } catch (Throwable e) { LOG.warn( "Could not replay acknowledge for message '" + messageAck.getLastMessageId() + "'. Message may have already been acknowledged. reason: " + e); } }
@Override public void acknowledge(ConsumerBrokerExchange consumerExchange, MessageAck ack) throws Exception { if (isLogAll() || isLogConsumerEvents()) { LOG.info( "Acknowledging message for client ID: {}{}", consumerExchange.getConnectionContext().getClientId(), (ack.getMessageCount() == 1 ? ", " + ack.getLastMessageId() : "")); if (ack.getMessageCount() > 1) { LOG.trace( "Message count: {}, First Message Id: {}, Last Message Id: {}", new Object[] {ack.getMessageCount(), ack.getFirstMessageId(), ack.getLastMessageId()}); } } super.acknowledge(consumerExchange, ack); }
final void removeMessage(final MessageAck ack, final RecordLocation location) { synchronized (this) { lastLocation = location; MessageId id = ack.getLastMessageId(); Message message = messages.remove(id); if (message == null) { messageAcks.add(ack); } else { message.decrementReferenceCount(); } } }
public void acknowledge(MessageAck ack) throws Exception { MessageId first = ack.getFirstMessageId(); MessageId lastm = ack.getLastMessageId(); TransactionId tid = ack.getTransactionId(); boolean isLocalTx = (tid != null) && tid.isLocalTransaction(); boolean single = lastm.equals(first); MessageInfo mi = null; int n = 0; if (ack.isIndividualAck()) { Iterator<MessageInfo> iter = deliveringRefs.iterator(); while (iter.hasNext()) { mi = iter.next(); if (mi.amqId.equals(lastm)) { n++; iter.remove(); session.getCoreSession().individualAcknowledge(nativeId, mi.nativeId); session.getCoreSession().commit(); break; } } } else if (ack.isRedeliveredAck()) { // client tells that this message is for redlivery. // do nothing until poisoned. n = 1; } else if (ack.isPoisonAck()) { // send to dlq Iterator<MessageInfo> iter = deliveringRefs.iterator(); boolean firstFound = false; while (iter.hasNext()) { mi = iter.next(); if (mi.amqId.equals(first)) { n++; iter.remove(); session .getCoreSession() .moveToDeadLetterAddress(nativeId, mi.nativeId, ack.getPoisonCause()); session.getCoreSession().commit(); if (single) { break; } firstFound = true; } else if (firstFound || first == null) { n++; iter.remove(); session .getCoreSession() .moveToDeadLetterAddress(nativeId, mi.nativeId, ack.getPoisonCause()); session.getCoreSession().commit(); if (mi.amqId.equals(lastm)) { break; } } } } else if (ack.isDeliveredAck() || ack.isExpiredAck()) { // ToDo: implement with tests n = 1; } else { Iterator<MessageInfo> iter = deliveringRefs.iterator(); boolean firstFound = false; while (iter.hasNext()) { MessageInfo ami = iter.next(); if (ami.amqId.equals(first)) { n++; if (!isLocalTx) { iter.remove(); } else { ami.setLocalAcked(true); } if (single) { mi = ami; break; } firstFound = true; } else if (firstFound || first == null) { n++; if (!isLocalTx) { iter.remove(); } else { ami.setLocalAcked(true); } if (ami.amqId.equals(lastm)) { mi = ami; break; } } } if (mi != null && !isLocalTx) { session.getCoreSession().acknowledge(nativeId, mi.nativeId); } } acquireCredit(n); }
public void removeMessage(ConnectionContext context, MessageAck ack) throws IOException { removeMessage(ack.getLastMessageId()); }