You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by akhettar <ay...@gmail.com> on 2016/02/16 15:18:27 UTC

Message Ack and Original Request correlation.

Hi

I have written a plugin (public final class MessageAuditorPlugin extends
BrokerPluginSupport). I audit the incoming message before sending to a queue
(override the send() method) and I have also overridden the acknowledge()
method - see code snippet below. The client is set to Auto Acknowledgement
mode. So as soon as the client consume the response and acknowledgement is
automatically sent to the broker and get's picked in the override method
below acknowledge(ConsumerBrokerExchange consumerExchange, final MessageAck
ack). 
I am looking for a way of correlating the original request to the
acknowledgement. 
Bear in mind the MessageAck doesn't contain a direct correlation Id to the
original request. It does have MessageId which is slightly different to that
the original Request - see below pattern. I could use the below pattern to
correlate request and acknowledgement but not sure if this is the best way?

Any direction is really appreciated.

Thanks

Ayache

*Message Id pattern*

*First Request:*

Request MessageId: ID:akhettar-58632-1455191246966-5:11:-1:1:1
Acknowledgement MessageId: ID:akhettar-58632-1455191246966-5:11:-1:1

*Second Request:*
Request MessageId: ID:akhettar-58632-1455191246966-5:11:-1:1:2
Acknowledgement MessageId: ID:akhettar-58632-1455191246966-5:11:-1:2

*Code Snippet*

/**
 * Message AuditWriter Interceptor. It audits message into Cassandra
datastore.
 */
public final class MessageAuditorPluginNew extends BrokerPluginSupport {

    @Override
    public void send(final ProducerBrokerExchange producerExchange, final
Message message) throws Exception {
        // audit the message
        super.send(producerExchange, message);
    }


    @Override
    public void acknowledge(final ConsumerBrokerExchange consumerExchange,
final MessageAck ack) throws Exception {
        // handle acknowledgment
        
        getNext().acknowledge(consumerExchange, ack);
    }

}



--
View this message in context: http://activemq.2283324.n4.nabble.com/Message-Ack-and-Original-Request-correlation-tp4707527.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Message Ack and Original Request correlation.

Posted by akhettar <ay...@gmail.com>.
Just for the benefit for anyone who may face the same issue. The alternative
solution is to override the messageConsumed(*,*) method. This will get
triggered for each message consumed by the client and you can apply filter
on whichever queue you're interested to listen on.

Enjoy



@Override
public void messageConsumed(final ConnectionContext context, final
MessageReference messageReference) {
        if (isOutDestination(messageReference) &&
!isPurged(messageReference)) {
            LOG.info("Recording acknowledgement for messageId: {}",
getProperties(messageReference.getMessage())
                    .get(TRANSACTION_ID));
            resetSessionIfClosed();
            auditor.update(messageReference.getMessage());
        }
        getNext().messageConsumed(context, messageReference);
}



--
View this message in context: http://activemq.2283324.n4.nabble.com/Message-Ack-and-Original-Request-correlation-tp4707527p4709906.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.