AMQ INDIVIDUAL_ACKNOWLEDGE Mode

434 Views Asked by At

I am using INDIVIDUAL_ACKNOWLEDGE mode to receive messages and manually acknowledge messages received from AMQ using C++ CMS library which implements JMS standards via Openwire protocol. I have got two consumers (Consumer 1, Consumer 2) receiving from same queue. When Consumer1 gets the message, Consumer ACKs the message. When I kill Consumer 1, Consumer 2 receives the message. I wouldn't have expected Consumer2 to receive it as it was already ACK'd. It looks like my call to acknowledge() is getting ignored.

Any clues or pointers will be helpful. Tried connecting to ActiveMQ 5.12.1 or Red Hat AMQ 7.2.1, same behaviour which shows that problem is not with Messaging Broker but my side. My call to acknowledge() is ignored.

Happy to provide any more information.

Here is Message Receiver call:

Definition:

        cms::Message* _textMessage;

Message Call:

MQMessage* AMQQueueInputService::getMessageConsumerReceiveSingle(long timeout)
{
        try
        {
                _textMessage = _receiverRef->receive(timeout);

                const cms::TextMessage* textMessage = dynamic_cast< const cms::TextMessage* > (_textMessage);

                if (_textMessage == NULL)
                        return NULL;

                MQMessage* mqMessage = new MQMessage(textMessage->getText(), getMessageProperties( textMessage ));

                return mqMessage;
        }
        catch (cms::CMSException& e)
        {
                throw (e);
        }
}

Ack Call:

bool AMQService::processMsgAck(Poco::Logger& logger)
{
        try
        {
                if (_textMessage != NULL)
                {
                        poco_information( logger,   format( " AMQService: Acknowledged CMSMessageId [%s]", _textMessage->getCMSMessageID() ) );
                        _textMessage->acknowledge(); //_sessionRef->getAcknowledgeMode() != cms::Session::AcknowledgeMode::AUTO_ACKNOWLEDGE

                        delete _textMessage;
                        _textMessage = NULL;

                        return true;

                }
        }
        catch (cms::CMSException& e)
        {
                e.printStackTrace();
                throw (e);
        }

}

Consumer1 Output:

enter image description here

Killed it.

Consumer2 Output:

enter image description here

1

There are 1 best solutions below

0
On

After painful testing, silly mistake. I was passing 3 from client process which is SESSION_TRANSACTED not INDIVIDUAL_ACKNOWLEDGE. I am using NetBeans where auto-complete shows the following (possibly alphabetic order). This caused me to pass 3 instead of 4.

NetBeansAutoComplete

Session.h in CMS clearly shows:

        enum AcknowledgeMode {

            AUTO_ACKNOWLEDGE,
            DUPS_OK_ACKNOWLEDGE,
            CLIENT_ACKNOWLEDGE,
            SESSION_TRANSACTED,
            INDIVIDUAL_ACKNOWLEDGE

        };