Does AMQ C++ Client (CMS) support multi-thread to ack message?

Solution Verified - Updated -

Issue

  • I am using OpenWire CMS client with CLIENT_ACK mode to acknowledge the message. I followed the official example . But since I need multi-thread processing, the default way of message acknowledge is a serial way, which means the thread could not acknowledge new messages if previous messages are not consumed. I need a parallel way to increate the application thoroughptut.
  • My sample code is as below:
void* sendAckThreadFunc(void *pMessage) {
    sleep(1);
    const Message* message = (const Message*) pMessage;
    message->acknowledge();
    printf("ACK sent out.");        
    return NULL;
}

 virtual void onMessage(const Message* message) {
        static int count = 0;
        try {
            count++;
            const TextMessage* textMessage = dynamic_cast<const TextMessage*>(message);
            string text = "";
            if (textMessage != NULL) {
                text = textMessage->getText();
            } else {
                text = "NOT A TEXTMESSAGE!";
            }
            if (clientAck) {          
                //message->acknowledge();  
        pthread_t sendAckThread; 
              //instead of ack the message in the onMessage function, use pthread_create to generate a new thread to ack the message
           if (pthread_create(&sendAckThread, NULL, sendAckThreadFunc,(void*) message)) {
        printf("Error occured when create threads.");
        }
            }

            printf("A Message #%d Received: %s\n", count, text.c_str());
        } catch (CMSException& e) {
            e.printStackTrace();
        }
    }

When running the consumer, we found the consumer application failed with below messages:

Segmentation fault (core dumped) 

and messages are not consumed.

Environment

  • Red Hat AMQ
    • 6.3
  • OpenWire ActiveMQ C++ Client (CMS)
    • 3.9.3

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content