AMQ INDIVIDUAL_ACKNOWLEDGE Mode

  activemq, amq, c++, content-management-system

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 or Red Hat AMQ, 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

Source: Windows Questions C++

LEAVE A COMMENT