You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by James Strachan <ja...@gmail.com> on 2008/02/04 14:38:15 UTC

Re: Async request/response using producerTemplate

On 30/01/2008, Sigmund <si...@gmail.com> wrote:
>
>
>
> RomKal wrote:
> >
> > 2008/1/28, Roman Kalukiewicz <ro...@gmail.com>:
> >> 2008/1/27, Sigmund <si...@gmail.com>:
> >> > Is it possible to do asynchronous JMS request/response using camel
> >> > producerTemplate i.e.
> >> > need to create temp queue and set JMSReplyTo, or is the only solution
> >> pure
> >> > JMS api?
> >>
> >> I believe it is possible by setting pattern property on the exchange you
> >> send.
> >>
> >> You can use template.send(String, Processor) method and in your
> >> processor you can do:
> >>
> >> ((DefaultExchange)exchange).setPattern(InOut);
> >>
> >> To clarify - what I write is not tested, and I don't have my eclipse
> >> at the moment so if there are some methods that are named in a
> >> different way, that find the proper one. Anyway SOMETHING like this
> >> should work.
> >
> > Ah - and one more thing - it is definitely not asynchronous then, but
> > as far as I know JMSEndpoint doesn't support asynchronous invocations
> > so far..
> > But no need to set JMSReplyTo manually using JMS interfaces ;)
> >
> > Roman
> >
> >
>
> Thanks,
>
> By default the producer returns an object as the sent message, do I use the
> exchange to set another
> if I like to return something else, like i.e. an ID? The consumer implements
> Processor I guess. Can you
> provide a simple example? The docs are not too clear on this..

FWIW if you've looked at Lingo, then Camel hasn't quite caught up to
all the clever async things Lingo does on JMS; but we're getting
closer all the time.

Right now as Roman said if you send a message exchange to a JMS
endpoint with InOut set as the pattern on the Exchange then internally
it creates a temporary queue and does the request/response thing.
However the caller is synchronous; it will block for the response.

For one way messaging (say an async method invocation) then you just
use the InOnly message exchange pattern (so that the caller does not
block for the result).

If we wanted a truly asynchronous client side mechanism; we'd need to
use 2 Camel endpoints or something; one for a oneway request and one
to receive the asynchronous response.

Do you really want asynchronous request/reply or just to switch
between InOut and InOnly for async oneways?

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

Open Source Integration
http://open.iona.com

Re: Camel Route Editor

Posted by James Strachan <ja...@gmail.com>.
On 06/02/2008, Jeff Gunther <Je...@intalgent.com> wrote:
> Is anyone currently working on a Camel based route editor like
> ServiceMix's CIMERO editor?

I know Oisin Hurley has experimented adding Camel to CIMERO - I'm not
sure how far he got though :). Hopefully we can use CIMERO to design
Camel routes. CIMERO kinda has a pluggable model for how the EIP route
is implemented on different ESBs/JBI providers etc.

Do you fancy helping out? :)

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

Open Source Integration
http://open.iona.com

Camel Route Editor

Posted by Jeff Gunther <Je...@intalgent.com>.
Is anyone currently working on a Camel based route editor like  
ServiceMix's CIMERO editor?

Jeff Gunther

Re: Async request/response using producerTemplate

Posted by James Strachan <ja...@gmail.com>.
On 07/02/2008, Sigmund <si...@gmail.com> wrote:
>
> Found the problem, classpath issues/camel version. Got it working.

Awesome, thanks for letting us know :)

I was thinking it might make a nice little demo showing folks how to
use the ProducerTemplate to interact with some JMS service. So much to
do, such little time :)

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

Open Source Integration
http://open.iona.com

Re: Async request/response using producerTemplate

Posted by Sigmund <si...@gmail.com>.
Found the problem, classpath issues/camel version. Got it working.

/S


Sigmund wrote:
> 
> Either way I try I get a class cast exception on the client side..
> 
> Client
> Long cryptoSendingId = (Long) producer.sendBody("jms:encryptQueue",
> cryptoSending);
> 
> implementing Processor on the server side and using this impl. also gives
> class cast exc.
>  
>    public void process(Exchange exchange) throws Exception {
>         log.debug("process");
>         Message out = exchange.getOut(true);
>         out.setBody(new Long(1L)); // test
>     }
> 
> In the case below I guess the return type must match the argument passed
> to the method?
> 
>     @MessageDriven(uri = "jms:encryptQueue")
>     public Long encrypt(CryptoSending cryptoSending) {
>         log.debug("encrypt");
>         return new Long(1L);
>     }
> 
> /S
> 
> 
> Sigmund wrote:
>> 
>> Hmm, tries just that before. I'll give it a try again.
>> 
>> Thanks
>> 
>> /S
>> 
>> 
>> James.Strachan wrote:
>>> 
>>> On 04/02/2008, Sigmund <si...@gmail.com> wrote:
>>>>
>>>> I can manage with synchronous, but how do I set the response to be sent
>>>> back?
>>> 
>>> So the ProducerTemplate is the client side; it sends the request and
>>> receives the response.
>>> 
>>> Its the server side which takes the request object and sets the
>>> response. To implement the server side in Camel you'd use a route.
>>> 
>>> from("jms:someQueue").process(new Processor() {
>>>   public void process(Exchange exchange) {
>>>      Message out = exchange.getOut(true);
>>>      out.setBody(someResponseObject);
>>>    }
>>> };
>>> 
>>> or even easier is to use a Java bean method...
>>> 
>>> public class Foo {
>>> 
>>>  @MessageDriven(uri="jms:someQueue")
>>>   public String getResponse(String request) {...}
>>> }
>>> 
>>> See
>>> http://activemq.apache.org/camel/bean-integration.html
>>> 
>>> -- 
>>> James
>>> -------
>>> http://macstrac.blogspot.com/
>>> 
>>> Open Source Integration
>>> http://open.iona.com
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Async-request-response-using-producerTemplate-tp15117797s22882p15332220.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Async request/response using producerTemplate

Posted by Sigmund <si...@gmail.com>.
Either way I try I get a class cast exception on the client side..

Client
Long cryptoSendingId = (Long) producer.sendBody("jms:encryptQueue",
cryptoSending);

implementing Processor on the server side and using this impl. also gives
class cast exc.
 
   public void process(Exchange exchange) throws Exception {
        log.debug("process");
        Message out = exchange.getOut(true);
        out.setBody(new Long(1L)); // test
    }

In the case below I guess the return type must match the argument passed to
the method?

    @MessageDriven(uri = "jms:encryptQueue")
    public Long encrypt(CryptoSending cryptoSending) {
        log.debug("encrypt");
        return new Long(1L);
    }

/S


Sigmund wrote:
> 
> Hmm, tries just that before. I'll give it a try again.
> 
> Thanks
> 
> /S
> 
> 
> James.Strachan wrote:
>> 
>> On 04/02/2008, Sigmund <si...@gmail.com> wrote:
>>>
>>> I can manage with synchronous, but how do I set the response to be sent
>>> back?
>> 
>> So the ProducerTemplate is the client side; it sends the request and
>> receives the response.
>> 
>> Its the server side which takes the request object and sets the
>> response. To implement the server side in Camel you'd use a route.
>> 
>> from("jms:someQueue").process(new Processor() {
>>   public void process(Exchange exchange) {
>>      Message out = exchange.getOut(true);
>>      out.setBody(someResponseObject);
>>    }
>> };
>> 
>> or even easier is to use a Java bean method...
>> 
>> public class Foo {
>> 
>>  @MessageDriven(uri="jms:someQueue")
>>   public String getResponse(String request) {...}
>> }
>> 
>> See
>> http://activemq.apache.org/camel/bean-integration.html
>> 
>> -- 
>> James
>> -------
>> http://macstrac.blogspot.com/
>> 
>> Open Source Integration
>> http://open.iona.com
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Async-request-response-using-producerTemplate-tp15117797s22882p15276085.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Async request/response using producerTemplate

Posted by Sigmund <si...@gmail.com>.
Hmm, tries just that before. I'll give it a try again.

Thanks

/S


James.Strachan wrote:
> 
> On 04/02/2008, Sigmund <si...@gmail.com> wrote:
>>
>> I can manage with synchronous, but how do I set the response to be sent
>> back?
> 
> So the ProducerTemplate is the client side; it sends the request and
> receives the response.
> 
> Its the server side which takes the request object and sets the
> response. To implement the server side in Camel you'd use a route.
> 
> from("jms:someQueue").process(new Processor() {
>   public void process(Exchange exchange) {
>      Message out = exchange.getOut(true);
>      out.setBody(someResponseObject);
>    }
> };
> 
> or even easier is to use a Java bean method...
> 
> public class Foo {
> 
>  @MessageDriven(uri="jms:someQueue")
>   public String getResponse(String request) {...}
> }
> 
> See
> http://activemq.apache.org/camel/bean-integration.html
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Async-request-response-using-producerTemplate-tp15117797s22882p15268865.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Async request/response using producerTemplate

Posted by James Strachan <ja...@gmail.com>.
On 04/02/2008, Sigmund <si...@gmail.com> wrote:
>
> I can manage with synchronous, but how do I set the response to be sent back?

So the ProducerTemplate is the client side; it sends the request and
receives the response.

Its the server side which takes the request object and sets the
response. To implement the server side in Camel you'd use a route.

from("jms:someQueue").process(new Processor() {
  public void process(Exchange exchange) {
     Message out = exchange.getOut(true);
     out.setBody(someResponseObject);
   }
};

or even easier is to use a Java bean method...

public class Foo {

 @MessageDriven(uri="jms:someQueue")
  public String getResponse(String request) {...}
}

See
http://activemq.apache.org/camel/bean-integration.html

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

Open Source Integration
http://open.iona.com

Re: Async request/response using producerTemplate

Posted by Sigmund <si...@gmail.com>.
I can manage with synchronous, but how do I set the response to be sent back?
Now it seems to return a copy of the instance I passed in, i.e. I send an
EncryptionRequest object and need a Long to be passade back either as a
Long,
an EncryptionResponse or as a propertie set on the EncryptionRequest.. How
do
I do that?

Thanks

/S

James.Strachan wrote:
> 
> On 30/01/2008, Sigmund <si...@gmail.com> wrote:
>>
>>
>>
>> RomKal wrote:
>> >
>> > 2008/1/28, Roman Kalukiewicz <ro...@gmail.com>:
>> >> 2008/1/27, Sigmund <si...@gmail.com>:
>> >> > Is it possible to do asynchronous JMS request/response using camel
>> >> > producerTemplate i.e.
>> >> > need to create temp queue and set JMSReplyTo, or is the only
>> solution
>> >> pure
>> >> > JMS api?
>> >>
>> >> I believe it is possible by setting pattern property on the exchange
>> you
>> >> send.
>> >>
>> >> You can use template.send(String, Processor) method and in your
>> >> processor you can do:
>> >>
>> >> ((DefaultExchange)exchange).setPattern(InOut);
>> >>
>> >> To clarify - what I write is not tested, and I don't have my eclipse
>> >> at the moment so if there are some methods that are named in a
>> >> different way, that find the proper one. Anyway SOMETHING like this
>> >> should work.
>> >
>> > Ah - and one more thing - it is definitely not asynchronous then, but
>> > as far as I know JMSEndpoint doesn't support asynchronous invocations
>> > so far..
>> > But no need to set JMSReplyTo manually using JMS interfaces ;)
>> >
>> > Roman
>> >
>> >
>>
>> Thanks,
>>
>> By default the producer returns an object as the sent message, do I use
>> the
>> exchange to set another
>> if I like to return something else, like i.e. an ID? The consumer
>> implements
>> Processor I guess. Can you
>> provide a simple example? The docs are not too clear on this..
> 
> FWIW if you've looked at Lingo, then Camel hasn't quite caught up to
> all the clever async things Lingo does on JMS; but we're getting
> closer all the time.
> 
> Right now as Roman said if you send a message exchange to a JMS
> endpoint with InOut set as the pattern on the Exchange then internally
> it creates a temporary queue and does the request/response thing.
> However the caller is synchronous; it will block for the response.
> 
> For one way messaging (say an async method invocation) then you just
> use the InOnly message exchange pattern (so that the caller does not
> block for the result).
> 
> If we wanted a truly asynchronous client side mechanism; we'd need to
> use 2 Camel endpoints or something; one for a oneway request and one
> to receive the asynchronous response.
> 
> Do you really want asynchronous request/reply or just to switch
> between InOut and InOnly for async oneways?
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Async-request-response-using-producerTemplate-tp15117797s22882p15268358.html
Sent from the Camel - Users mailing list archive at Nabble.com.