You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Marcin W." <mw...@gmail.com> on 2025/09/19 10:10:29 UTC

JMS request-reply correlation with custom headers

Hi,

I have stumbled upon the following problem. Our legacy platform uses
JMS with Artemis server for request-reply scenarios. However, it uses
custom headers instead of "JMSMessageID" and "JMSCorrelationId" for
request-reply correlation. Request includes "msgId" header that is
being copied to "corrId" header of the response message by the service
provider. Service client wait for the reply with selector
"corrId=<msgId>".

I have found two properties on JMS Component that looked promising:

1. correlationProperty = corrId
2. replyToDestinationSelectorName = corrId

But:

1. Does not change the header's name used by selector, only uses the
value of the specified header (keeps listening with selector
"JMSCorrelationID=<corrId-from-request>")
2. Listens on correct header but with it's value from request:
"corrId=<corrId-from-request-but-regenerated>" which would be ok but
it also overwrites the value of "corrId" you set before sending the
message (I set "msgId" to the same value as "corrId" because as I
mentioned the providing service copies the value of "msgId" to
"corrId")

I found the following code responsible for this behaviour:

1. org.apache.camel.component.jms.reply.MessageSelectorCreator.get()
where "JMSCorrelationId" is hardcoded.
2. org.apache.camel.component.jms.reply.QueueReplyManager.createDefaultListenerContainer()
where replyToSelectorValue is always generated as new.

I found solution that works by using to() with "InOnly" and
pollEnrich() with custom selector, but it is not the best solution I
think (pollEnrich creates new consumer each time it receives and I
think sometime it happens too late and the response that go to the
response topic (address in Artemis nomenclature) cannot be routed
because customer queue is not created yet and therefore message is
discarded) .

Is there another solution that could work in my scenario? Using
synchronous to() would be the best and cleanest.

Kind regards,
Marcin Wieckowski.

Re: JMS request-reply correlation with custom headers

Posted by Marcin Więckowski <mw...@gmail.com>.
Hi,

I have created a pull request:
https://github.com/apache/camel/pull/19446. The new feature does the
trick for me.

Pozdrawiam,
Marcin Więckowski.

Re: JMS request-reply correlation with custom headers

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Sep 30, 2025 at 2:35 PM Marcin Więckowski <mw...@gmail.com>
wrote:

> Thank you for confirmation. I will do that and maybe propose a configurable
> option for the future release.
>
>
You are welcome to share how its going for you.



>
> Pozdrawiam,
> Marcin Więckowski.
>
> pt., 26 wrz 2025, 10:20 użytkownik Claus Ibsen <cl...@gmail.com>
> napisał:
>
> > Hi
> >
> > You can try to patch the code and change that selector to use your custom
> > header name, and see how that goes.
> > Then maybe we can make this configurable in a future Camel release.
> >
> >
> > On Fri, Sep 19, 2025 at 12:11 PM Marcin W. <mw...@gmail.com> wrote:
> >
> > > Hi,
> > >
> > > I have stumbled upon the following problem. Our legacy platform uses
> > > JMS with Artemis server for request-reply scenarios. However, it uses
> > > custom headers instead of "JMSMessageID" and "JMSCorrelationId" for
> > > request-reply correlation. Request includes "msgId" header that is
> > > being copied to "corrId" header of the response message by the service
> > > provider. Service client wait for the reply with selector
> > > "corrId=<msgId>".
> > >
> > > I have found two properties on JMS Component that looked promising:
> > >
> > > 1. correlationProperty = corrId
> > > 2. replyToDestinationSelectorName = corrId
> > >
> > > But:
> > >
> > > 1. Does not change the header's name used by selector, only uses the
> > > value of the specified header (keeps listening with selector
> > > "JMSCorrelationID=<corrId-from-request>")
> > > 2. Listens on correct header but with it's value from request:
> > > "corrId=<corrId-from-request-but-regenerated>" which would be ok but
> > > it also overwrites the value of "corrId" you set before sending the
> > > message (I set "msgId" to the same value as "corrId" because as I
> > > mentioned the providing service copies the value of "msgId" to
> > > "corrId")
> > >
> > > I found the following code responsible for this behaviour:
> > >
> > > 1. org.apache.camel.component.jms.reply.MessageSelectorCreator.get()
> > > where "JMSCorrelationId" is hardcoded.
> > > 2.
> > >
> >
> org.apache.camel.component.jms.reply.QueueReplyManager.createDefaultListenerContainer()
> > > where replyToSelectorValue is always generated as new.
> > >
> > > I found solution that works by using to() with "InOnly" and
> > > pollEnrich() with custom selector, but it is not the best solution I
> > > think (pollEnrich creates new consumer each time it receives and I
> > > think sometime it happens too late and the response that go to the
> > > response topic (address in Artemis nomenclature) cannot be routed
> > > because customer queue is not created yet and therefore message is
> > > discarded) .
> > >
> > > Is there another solution that could work in my scenario? Using
> > > synchronous to() would be the best and cleanest.
> > >
> > > Kind regards,
> > > Marcin Wieckowski.
> > >
> >
> >
> > --
> > Claus Ibsen
> >
>


-- 
Claus Ibsen

Re: JMS request-reply correlation with custom headers

Posted by Marcin Więckowski <mw...@gmail.com>.
Thank you for confirmation. I will do that and maybe propose a configurable
option for the future release.


Pozdrawiam,
Marcin Więckowski.

pt., 26 wrz 2025, 10:20 użytkownik Claus Ibsen <cl...@gmail.com>
napisał:

> Hi
>
> You can try to patch the code and change that selector to use your custom
> header name, and see how that goes.
> Then maybe we can make this configurable in a future Camel release.
>
>
> On Fri, Sep 19, 2025 at 12:11 PM Marcin W. <mw...@gmail.com> wrote:
>
> > Hi,
> >
> > I have stumbled upon the following problem. Our legacy platform uses
> > JMS with Artemis server for request-reply scenarios. However, it uses
> > custom headers instead of "JMSMessageID" and "JMSCorrelationId" for
> > request-reply correlation. Request includes "msgId" header that is
> > being copied to "corrId" header of the response message by the service
> > provider. Service client wait for the reply with selector
> > "corrId=<msgId>".
> >
> > I have found two properties on JMS Component that looked promising:
> >
> > 1. correlationProperty = corrId
> > 2. replyToDestinationSelectorName = corrId
> >
> > But:
> >
> > 1. Does not change the header's name used by selector, only uses the
> > value of the specified header (keeps listening with selector
> > "JMSCorrelationID=<corrId-from-request>")
> > 2. Listens on correct header but with it's value from request:
> > "corrId=<corrId-from-request-but-regenerated>" which would be ok but
> > it also overwrites the value of "corrId" you set before sending the
> > message (I set "msgId" to the same value as "corrId" because as I
> > mentioned the providing service copies the value of "msgId" to
> > "corrId")
> >
> > I found the following code responsible for this behaviour:
> >
> > 1. org.apache.camel.component.jms.reply.MessageSelectorCreator.get()
> > where "JMSCorrelationId" is hardcoded.
> > 2.
> >
> org.apache.camel.component.jms.reply.QueueReplyManager.createDefaultListenerContainer()
> > where replyToSelectorValue is always generated as new.
> >
> > I found solution that works by using to() with "InOnly" and
> > pollEnrich() with custom selector, but it is not the best solution I
> > think (pollEnrich creates new consumer each time it receives and I
> > think sometime it happens too late and the response that go to the
> > response topic (address in Artemis nomenclature) cannot be routed
> > because customer queue is not created yet and therefore message is
> > discarded) .
> >
> > Is there another solution that could work in my scenario? Using
> > synchronous to() would be the best and cleanest.
> >
> > Kind regards,
> > Marcin Wieckowski.
> >
>
>
> --
> Claus Ibsen
>

Re: JMS request-reply correlation with custom headers

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You can try to patch the code and change that selector to use your custom
header name, and see how that goes.
Then maybe we can make this configurable in a future Camel release.


On Fri, Sep 19, 2025 at 12:11 PM Marcin W. <mw...@gmail.com> wrote:

> Hi,
>
> I have stumbled upon the following problem. Our legacy platform uses
> JMS with Artemis server for request-reply scenarios. However, it uses
> custom headers instead of "JMSMessageID" and "JMSCorrelationId" for
> request-reply correlation. Request includes "msgId" header that is
> being copied to "corrId" header of the response message by the service
> provider. Service client wait for the reply with selector
> "corrId=<msgId>".
>
> I have found two properties on JMS Component that looked promising:
>
> 1. correlationProperty = corrId
> 2. replyToDestinationSelectorName = corrId
>
> But:
>
> 1. Does not change the header's name used by selector, only uses the
> value of the specified header (keeps listening with selector
> "JMSCorrelationID=<corrId-from-request>")
> 2. Listens on correct header but with it's value from request:
> "corrId=<corrId-from-request-but-regenerated>" which would be ok but
> it also overwrites the value of "corrId" you set before sending the
> message (I set "msgId" to the same value as "corrId" because as I
> mentioned the providing service copies the value of "msgId" to
> "corrId")
>
> I found the following code responsible for this behaviour:
>
> 1. org.apache.camel.component.jms.reply.MessageSelectorCreator.get()
> where "JMSCorrelationId" is hardcoded.
> 2.
> org.apache.camel.component.jms.reply.QueueReplyManager.createDefaultListenerContainer()
> where replyToSelectorValue is always generated as new.
>
> I found solution that works by using to() with "InOnly" and
> pollEnrich() with custom selector, but it is not the best solution I
> think (pollEnrich creates new consumer each time it receives and I
> think sometime it happens too late and the response that go to the
> response topic (address in Artemis nomenclature) cannot be routed
> because customer queue is not created yet and therefore message is
> discarded) .
>
> Is there another solution that could work in my scenario? Using
> synchronous to() would be the best and cleanest.
>
> Kind regards,
> Marcin Wieckowski.
>


-- 
Claus Ibsen

Re: JMS request-reply correlation with custom headers

Posted by Marcin Więckowski <mw...@gmail.com>.
Just to make it easier to see what I need I created a sample project.

Main part is:

from("direct:" + scenario)
        .log("Sending request to: " + requestEndpoint)
        .to(requestEndpoint);

from("jms:queue:request-" + scenario)
        .log("Received request on: jms:queue:request-" + scenario +
"\n${logExchange}")
        .setHeader("corrId").simple("${header.msgId}");

And my question is what can I do to make it work without changing the
second route, and keeping only "to()" in the first route and not
changing it to "to().inOnly() + pollEnrich()".

Link to the project:

https://drive.google.com/file/d/11ljZKEb6FvlHoWj01tOSgF0Sz8eujBXP/view?usp=sharing

Kind regards,
Marcin Wieckowski.