JustNatural
JustNatural

Reputation: 448

JMeter JMS Publisher: Getting the JMSMessageId (generated at runtime) in the header and using it as the value of another JMS Property before publish

In JMeter, I have a JMS Publisher sampler configured to send a message to a remote queue. The message gets successfully published to the remote queue running on an ActiveMQ Artemis server and in the View Results Tree listener (Request -> Request Headers) I can see some JMS properties (which I set in the JMS Properties section of the JMS Publisher sampler). However, some of these header properties I see, I have never set (They are implicitly set by the JMS Publisher sampler): JMSMessageId, JMSTimestamp, JMSType, JMSExpiration.

JMSMessageId looks like this:

JMSMessageId     ID:ip-100-100-100-100.eu-west-1.compute.internal-44444-1111111111111-2:2:2:1:1

I understand that this JMSMessageId header gets generated at runtime and its generation rules depends on the JMS vendor. It may only be unique for the current installation of the message server, or it may be universally unique.

I would like to know if I could get the value of the JMSMessageId property after it's generated and use it as a value for another JSM Property named JMSCorrelationID, before the message is published.

Upvotes: 0

Views: 128

Answers (2)

Justin Bertram
Justin Bertram

Reputation: 35123

In order to get the JMSMessageID that's generated for the message by the provider you need to invoke getJMSMessageID(). However, in order to use this value for another header or property on the message you'd have to invoke this method before the message is sent. The problem is that the provider-assigned value for JMSMessageID is not available until after the message is sent. The JavaDoc for getJMSMessageID() states:

When the send or publish method returns, it contains a provider-assigned value.

Therefore, you can't use the JMSMessageID for any other header or property value on the same message.

Upvotes: 3

Ivan G
Ivan G

Reputation: 2847

In the vast majority of cases messageId and correlationId are not connected.

Take a look at documentation:

Using the correlation ID

A correlation ID is used to correlate response messages with request messages when an application invokes a request-response operation. With WebSphere® MQ and WebSphere MQ JMS, you can correlate using either a correlation ID or a message ID. In most cases, the caller lets the queue manager select a message ID and expects the application to copy this message ID into the correlation ID of the response message. But there are other possibilities. A caller could specify a specific value in the correlation ID and expect this value to be copied into the response correlation ID. The caller might also require that the message ID of the request message be copied to the message ID of the response message.

So instead of trying to get the value generated by the MQ system or library you can pre-generate it somehow and set it yourself. In this case you can use While Controller wait until the message is available in the queue and Transaction Controller to measure end-to-end message processing time

Upvotes: 0

Related Questions