My C++ application needs to do request-response communication with an external application via ActiveMQ Artemis. I am using the activemq-cpp library. The external app copies JMSMessageID
of the request to JMSCorrelationID
of the response. I am trying to identify the response by saving the JMSMessageID
of the request after being sent, and using a selector for this ID in the consumer.
std::unique_ptr<cms::TextMessage> request;
std::unique_ptr<cms::MessageProducer> msgProducer;
//...
msgProducer->send(request.get());
std::string messageid = request->getCMSMessageID();
//...
std::unique_ptr<cms::MessageConsumer> msgConsumer(
session->createConsumer(queue, "JMSCorrelationID = '" + messageid + "'"));
const cms::Message * message = msgConsumer->receive(timeoutSeconds * 1000);
Unfortunately the message ID returned by getCMSMessageID()
(ID:hostname.xy.hu-12445-1718189421186-0:0:1:1:1
) is different from the ID generated on the broker side (ID:ad50ab28-28a3-11ef-a29a-0a580a800369
). How is it supposed to work? I cannot change the behavior of the external application or the broker, so it is not an option that JMSCorrelationID
of the response is filled differently. I don't have the necessary permissions to create temporary queues either.
The issue at hand would appear to be that you have clients of differing protocols sending to the broker and are assuming that those protocols share the same message ID formats. The CMS client uses the Openwire protocol and has a very specific message ID format that doesn't appear to be what the sending client is using ("ID:ad50ab28-28a3-11ef-a29a-0a580a800369") which looks more like it might be from the Core client or perhaps an AMQP client.
When mixing protocol clients you cannot rely on the JMS Message ID to be static as there is likely going to be translation between those protocols that will alter the ID values used. You would be better served by using a message property with a format your teams settle on as the correlation and selector targets