You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by mta38 <mt...@orange-ftgroup.com> on 2009/01/08 18:33:27 UTC

Thread , Request/Response

Hi all,
Is there a way to do a request/reply request in a thread?
In fact in my thread I create a request and I want to send this request to a
camel route (via a camel context) and I want to be "blocked" until I receive
the response.
Is someone having an idea?
Best regards
Mta38

-- 
View this message in context: http://www.nabble.com/Thread-%2C-Request-Response-tp21356633s22882p21356633.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Thread , Request/Response

Posted by Willem Jiang <wi...@gmail.com>.
I think Camel already support that [1].
And you can use producer  template to do that.

[1] http://activemq.apache.org/camel/request-reply.html
[2] http://activemq.apache.org/camel/producertemplate.html

Willem

mta38 wrote:
> Hi all,
> Is there a way to do a request/reply request in a thread?
> In fact in my thread I create a request and I want to send this request to a
> camel route (via a camel context) and I want to be "blocked" until I receive
> the response.
> Is someone having an idea?
> Best regards
> Mta38
> 


Re: Thread , Request/Response

Posted by James Strachan <ja...@gmail.com>.
2009/1/14 mta38 <mt...@orange-ftgroup.com>:
>
> Thanks Ibsen and Willem for your answer,
> I already try PollingConsumer class, but it does not correspond to my
> problem.
> Really, I want that a client send a request (with a correlation ID 10 for
> example) and block until it receives a response with the same correlation
> ID, such as a selector in JMS.
> In other words, Is Jms component is the only which permit to use selector?

BTW using a selector to implement request/response is pretty
sub-optimal; since it typically means you're gonna be creating/closing
a consumer for each message you send; which involves lots of
chattiness with the broker.

More background and detail here - it also describes how the JMS
endpoint in camel implements efficient request-reponse.
http://activemq.apache.org/how-should-i-implement-request-response-with-jms.html

Basically a single temporary queue is used to send all the replies to
the same JVM as made the request; then a multiplexer uses the
correlationID of returned messages to pass it to the correct thread.

If we want to mimic this behaviour on other transports, I'd suggest
doing something similar (without selectors).  e.g. telling the server
to respond to an endpoint within the JVM of the client (preferably the
thread too if possible) - then have an optional multiplexer that
matches the replies to the right requesting thread. I'm sure we could
refactor the request-reply code in the JMS endpoint (particularly the
code which adds a unique correlation ID and maintains the request
Future Map of IDs so when a reply comes back we know which thread to
wake up etc).

For example we could use a single MINA/HTTP/XMPP endpoint consuming
all replies for any thread - then use a multiplexer to map which
response goes to which thread thats blocked (as you could do
concurrent request/replies in different threads).

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/

Re: Thread , Request/Response

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jan 14, 2009 at 9:24 AM, mta38 <mt...@orange-ftgroup.com> wrote:
>
> Thanks Ibsen and Willem for your answer,
> I already try PollingConsumer class, but it does not correspond to my
> problem.
> Really, I want that a client send a request (with a correlation ID 10 for
> example) and block until it receives a response with the same correlation
> ID, such as a selector in JMS.
> In other words, Is Jms component is the only which permit to use selector?
Yeah as it is a part of the JMS spec.

Otherwise you can use a filter to implement the selector and send OK
data to a seda queue
and have a consumer on the seda queue

from(x).filter(header("xxx").isEqualTo("foo")).to("seda:yeah")

from"seda:yeah")...

The filter can use all kind of Expression and Predicate so you can
invoke a bean (POJO) and let it determine true|false if the exchange
should be filtered or not.

http://activemq.apache.org/camel/message-filter.html

If you dont wanna LOSE unfiltered messages, you can use a choice and
route the false messages into another destination


James you got any good ideas?





>
> Best Regards,
>
> Mta38
>
>
>
>
>
> Claus Ibsen-2 wrote:
>>
>> Hi
>>
>> Yeah using the org.apache.camel.PollingConsumer - it can block until a
>> message arrives, or until a given timeout.
>>
>> It requires however that you use the Camel API a bit to use it instead
>> of the route or producer template.
>>
>> We have a sample of this with the FTP component where it will wait
>> until there is a file to download
>> http://activemq.apache.org/camel/ftp.html
>>
>>
>>
>> On Thu, Jan 8, 2009 at 6:33 PM, mta38 <mt...@orange-ftgroup.com>
>> wrote:
>>>
>>> Hi all,
>>> Is there a way to do a request/reply request in a thread?
>>> In fact in my thread I create a request and I want to send this request
>>> to a
>>> camel route (via a camel context) and I want to be "blocked" until I
>>> receive
>>> the response.
>>> Is someone having an idea?
>>> Best regards
>>> Mta38
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Thread-%2C-Request-Response-tp21356633s22882p21356633.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>>
>> /Claus Ibsen
>> Apache Camel Committer
>> Blog: http://davsclaus.blogspot.com/
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Thread-%2C-Request-Response-tp21356633s22882p21451725.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 

/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/

Re: Thread , Request/Response

Posted by mta38 <mt...@orange-ftgroup.com>.
Thanks Ibsen and Willem for your answer,
I already try PollingConsumer class, but it does not correspond to my
problem.
Really, I want that a client send a request (with a correlation ID 10 for
example) and block until it receives a response with the same correlation
ID, such as a selector in JMS.
In other words, Is Jms component is the only which permit to use selector?

Best Regards,

Mta38





Claus Ibsen-2 wrote:
> 
> Hi
> 
> Yeah using the org.apache.camel.PollingConsumer - it can block until a
> message arrives, or until a given timeout.
> 
> It requires however that you use the Camel API a bit to use it instead
> of the route or producer template.
> 
> We have a sample of this with the FTP component where it will wait
> until there is a file to download
> http://activemq.apache.org/camel/ftp.html
> 
> 
> 
> On Thu, Jan 8, 2009 at 6:33 PM, mta38 <mt...@orange-ftgroup.com>
> wrote:
>>
>> Hi all,
>> Is there a way to do a request/reply request in a thread?
>> In fact in my thread I create a request and I want to send this request
>> to a
>> camel route (via a camel context) and I want to be "blocked" until I
>> receive
>> the response.
>> Is someone having an idea?
>> Best regards
>> Mta38
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Thread-%2C-Request-Response-tp21356633s22882p21356633.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> 
> /Claus Ibsen
> Apache Camel Committer
> Blog: http://davsclaus.blogspot.com/
> 
> 

-- 
View this message in context: http://www.nabble.com/Thread-%2C-Request-Response-tp21356633s22882p21451725.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Thread , Request/Response

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

Yeah using the org.apache.camel.PollingConsumer - it can block until a
message arrives, or until a given timeout.

It requires however that you use the Camel API a bit to use it instead
of the route or producer template.

We have a sample of this with the FTP component where it will wait
until there is a file to download
http://activemq.apache.org/camel/ftp.html



On Thu, Jan 8, 2009 at 6:33 PM, mta38 <mt...@orange-ftgroup.com> wrote:
>
> Hi all,
> Is there a way to do a request/reply request in a thread?
> In fact in my thread I create a request and I want to send this request to a
> camel route (via a camel context) and I want to be "blocked" until I receive
> the response.
> Is someone having an idea?
> Best regards
> Mta38
>
> --
> View this message in context: http://www.nabble.com/Thread-%2C-Request-Response-tp21356633s22882p21356633.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 

/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/