Question

I'm using ActiveMQ for C++. In our planned design, we're going to consume messages, pass them on to some asynchronous processing and only then the message is considered as handled. We'd like to process more than one message in parallel - each will finish its processing in a different time - and ack only those that finished processing. This, in order to avoid losing messages when server goes down, process crashes etc.

From both documentation and testing, I understand that in both CLIENT_ACKNOWLEDGE and SESSION_TRANSACTED modes, there's no way to ack only one message. Is there a best practice for such cases? Should I hold a "session pool", each session handles one message at a time synchronously and then acks it?

Thanks.

Était-ce utile?

La solution

When you create a Session you can use the cms::Session acknowledgement mode INDIVIDUAL_ACKNOWLEDGE which allows you to ack a single Message. The cms::Message object has an acknowledge method you can use to ack each message.

cms::Session* session = connection.createSession(cms::Session::INDIVIDUAL_ACKNOWLEDGE);

To ack the Message:

cms::Message* message = consumer.receive();
message->acknowledge();

Autres conseils

Although I have never really implemented a concurrent consumer in C++ for ActiveMQ, it's the way you normally handle such cases in Java.

Create a number of different threads with a session and a message listener each that reads messages of the queue, does the processing and then commits the transaction (or acks if you don't want transactions).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top