You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by raulvk <ra...@atosorigin.com> on 2008/09/10 19:55:34 UTC

Synchronous/asynchronous bridge

Hi,

I am using Camel embedded in ServiceMix via the servicemix-camel service
engine.

I need to implement the following routing scenario:


HTTP Consumer BC   ---> Camel  --->  Transformation --> HTTP Provider BC
             /|\                      |
              |______________ |


Basically, I receive a SOAP request through an HTTP endpoint in ServiceMix
and it gets directed to Camel. As soon as Camel receives it, it should
immediately return back a fixed response (<Response>OK</Response>), and then
it should invoke an XSLT Transformer, and should finally send the
transformed message to the HTTP Provider.

I am OK with the bit where I have to use a pipeline, but I don't understand
how to return the response half-way through the routing flow.

Could someone help me with this, please?

Thanks a lot!

-- 
View this message in context: http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19415072.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Synchronous/asynchronous bridge

Posted by Roman Kalukiewicz <ro...@gmail.com>.
Hello,

I would say, that you shouldn't try to pool processors at all, as it
can be dangerous. Especially if processor implements
org.apache.camel.Service - who knows which instance would be
initialized? I guess there could be many different problems.

I believe that great mayority of processors are thread-safe, because
they doesn't have state at all (especially if you want to return
precomputed response). Even it you need pooling, then you should pool
some objects from inside your processor, as processors are obtained
once at configuration time.

Roman

2008/9/11 Claus Ibsen <ci...@silverbullet.dk>:
> Hi
>
> Doesn't spring have object pooling capabilities?
> http://static.springframework.org/spring/docs/2.5.x/reference/aop-api.html#aop-ts-pool
> But that might be a bit advanced with AOP and all the stuff.
>
> Apache has an object pool framework:
> http://commons.apache.org/pool/
>
>
>
> The .thead() is for route concurrency, not object instance pooling per se.
>
> If you use .thread(5) then you can have up till 5 concurrent threads doing the route at the same time.
>
> But if you XML to respond is the same in all situations then you can use the same shared instance for the 5 threads. In that regard the response is fixed (pre computed), and that you don't alter the response afterwards.
>
> But if you need to compute and alter the XML per. input message then you need your processor be either:
> - thread safe
> - locks for shared resources
> - multi instances of your processor = object pool
>
>
> But what high-load are we talking about?
>
> Maybe James, Gert has some good ideas? They tend to have seen it all ;)
>
>
>
> Med venlig hilsen
>
> Claus Ibsen
> ......................................
> Silverbullet
> Skovsgårdsvænget 21
> 8362 Hørning
> Tlf. +45 2962 7576
> Web: www.silverbullet.dk
>
> -----Original Message-----
> From: raulvk [mailto:raul.kripalani@atosorigin.com]
> Sent: 11. september 2008 13:17
> To: camel-user@activemq.apache.org
> Subject: RE: Synchronous/asynchronous bridge
>
>
> Ok, great! Since I am using the Java DSL, I will take the first approach.
>
> Is there a way to pool this object so that there are many instances and
> performance is not degraded under high-load circumstances? (I have seen
> thread() instructions in the Java DSL, but I am not sure whether these would
> be applicable in my scenario).
>
> Thanks.
>
>
> Claus Ibsen wrote:
>>
>> Hi
>>
>> Camel has a service interface: org.apache.camel.Service with callbacks for
>> start and stop = lifecycle. But I doubt that your processor will receive
>> these callback.
>>
>> 1)
>> If you don't use an anonymous inner class as processor you can just create
>> your processor instance once, and then init the XML.
>>
>> In the camel route you can pass a reference to your object with
>> .processRef()
>>
>> For example in your route builder (if using java):
>> Processor myProcessor = new MyProcessor();
>> myProcessor.myInit(); // init or do it in the constructor
>>
>> from("xxx").processRef(myProcessor).to("seda:yyy")...
>>
>>
>> 2)
>> If you are using Spring xml for lifecycle management then you can use
>> spring to handle this and in the Camel route you can use
>> .bean("mySpringBeanId") to invoke you bean where you can do you code as
>> the processor did.
>>
>> When you use bean then you is able to be less dependent on Camel
>> interfaces and in fact you can write it as a POJO with no imports for
>> Camel. Camel will invoke your method.
>>
>> from("xxx").bean("mySpringBeanId").to("seda:yyy")...
>>
>> See wiki doc
>> http://activemq.apache.org/camel/bean.html
>>
>>
>>
>>
>>
>> Med venlig hilsen
>>
>> Claus Ibsen
>> ......................................
>> Silverbullet
>> Skovsgårdsvænget 21
>> 8362 Hørning
>> Tlf. +45 2962 7576
>> Web: www.silverbullet.dk
>>
>> -----Original Message-----
>> From: raulvk [mailto:raul.kripalani@atosorigin.com]
>> Sent: 11. september 2008 12:54
>> To: camel-user@activemq.apache.org
>> Subject: RE: Synchronous/asynchronous bridge
>>
>>
>> Ok, got it half-working. Thanks!
>>
>> What I have actually done is I have created a private class inside that
>> implements Processor, and I am using the .process() DSL instruction to run
>> it through it.
>>
>> However, the problem I am facing now is that because the response is
>> actually returned to a CXF endpoint via ServiceMix, this endpoint expects
>> the message within an <jbi:message> ... </jbi:message> envelope.
>>
>> Therefore, the XML that I ought to send back is getting a bit more
>> complex.
>> I am thinking of loading the response XML from a file from the classpath.
>> I
>> could do this within the process() method, but this would keep loading and
>> discarding the XML over and over again, right?
>>
>> Do processors have lifecycle methods, such that I can load the XML into
>> memory once within an init() method?
>>
>> What solution do you suggest to only load the XML from the file into
>> memory
>> ONCE?
>>
>> Thank you!!
>>
>>
>>
>> Claus Ibsen wrote:
>>>
>>> Hi
>>>
>>> BTW: .transform is a new DSL in Camel 1.4. And since you are using
>>> ServiceMix it might not be with the latest Camel release.
>>>
>>> You can then use .setOutBody instead
>>>
>>>
>>> Med venlig hilsen
>>>
>>> Claus Ibsen
>>> ......................................
>>> Silverbullet
>>> Skovsgårdsvænget 21
>>> 8362 Hørning
>>> Tlf. +45 2962 7576
>>> Web: www.silverbullet.dk
>>>
>>> -----Original Message-----
>>> From: Claus Ibsen [mailto:ci@silverbullet.dk]
>>> Sent: 11. september 2008 08:49
>>> To: camel-user@activemq.apache.org
>>> Subject: RE: Synchronous/asynchronous bridge
>>>
>>> Hi
>>>
>>> Yes this is possible. The solution is to use a queue where you "split"
>>> the
>>> request. You can use a JMS queue or a the SEDA queues that Camel has
>>> out-of-the-box.
>>> http://activemq.apache.org/camel/seda.html
>>>
>>> The transform DSL is used for setting the OUT body = the response to the
>>> original caller.
>>>
>>>
>>> Here is an example of such a scenariou. I have build a unit test to
>>> demonstrate this:
>>>
>>>     public void testSendAsync() throws Exception {
>>>         MockEndpoint mock = getMockEndpoint("mock:result");
>>>         mock.expectedBodiesReceived("Hello World");
>>>
>>>         Object out = template.requestBody("direct:start", "Hello World");
>>>         assertEquals("OK", out);
>>>
>>>         assertMockEndpointsSatisfied();
>>>     }
>>>
>>>     @Override
>>>     protected RouteBuilder createRouteBuilder() throws Exception {
>>>         return new RouteBuilder() {
>>>             public void configure() throws Exception {
>>>                 from("direct:start")
>>>                     // send it to the seda queue that is async
>>>                     .to("seda:next")
>>>                     // return a constant response
>>>                     .transform(constant("OK"));
>>>
>>>                 from("seda:next").to("mock:result");
>>>             }
>>>         };
>>>     }
>>>
>>>
>>>
>>>
>>> Med venlig hilsen
>>>
>>> Claus Ibsen
>>> ......................................
>>> Silverbullet
>>> Skovsgårdsvænget 21
>>> 8362 Hørning
>>> Tlf. +45 2962 7576
>>> Web: www.silverbullet.dk
>>> -----Original Message-----
>>> From: raulvk [mailto:raul.kripalani@atosorigin.com]
>>> Sent: 10. september 2008 19:56
>>> To: camel-user@activemq.apache.org
>>> Subject: Synchronous/asynchronous bridge
>>>
>>>
>>> Hi,
>>>
>>> I am using Camel embedded in ServiceMix via the servicemix-camel service
>>> engine.
>>>
>>> I need to implement the following routing scenario:
>>>
>>>
>>> HTTP Consumer BC   ---> Camel  --->  Transformation --> HTTP Provider BC
>>>              /|\                      |
>>>               |______________ |
>>>
>>>
>>> Basically, I receive a SOAP request through an HTTP endpoint in
>>> ServiceMix
>>> and it gets directed to Camel. As soon as Camel receives it, it should
>>> immediately return back a fixed response (<Response>OK</Response>), and
>>> then
>>> it should invoke an XSLT Transformer, and should finally send the
>>> transformed message to the HTTP Provider.
>>>
>>> I am OK with the bit where I have to use a pipeline, but I don't
>>> understand
>>> how to return the response half-way through the routing flow.
>>>
>>> Could someone help me with this, please?
>>>
>>> Thanks a lot!
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19415072.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19432301.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19432640.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>

RE: Synchronous/asynchronous bridge

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

Doesn't spring have object pooling capabilities?
http://static.springframework.org/spring/docs/2.5.x/reference/aop-api.html#aop-ts-pool
But that might be a bit advanced with AOP and all the stuff.

Apache has an object pool framework:
http://commons.apache.org/pool/



The .thead() is for route concurrency, not object instance pooling per se.

If you use .thread(5) then you can have up till 5 concurrent threads doing the route at the same time.

But if you XML to respond is the same in all situations then you can use the same shared instance for the 5 threads. In that regard the response is fixed (pre computed), and that you don't alter the response afterwards.

But if you need to compute and alter the XML per. input message then you need your processor be either:
- thread safe
- locks for shared resources
- multi instances of your processor = object pool


But what high-load are we talking about? 

Maybe James, Gert has some good ideas? They tend to have seen it all ;)



Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: raulvk [mailto:raul.kripalani@atosorigin.com] 
Sent: 11. september 2008 13:17
To: camel-user@activemq.apache.org
Subject: RE: Synchronous/asynchronous bridge


Ok, great! Since I am using the Java DSL, I will take the first approach.

Is there a way to pool this object so that there are many instances and
performance is not degraded under high-load circumstances? (I have seen
thread() instructions in the Java DSL, but I am not sure whether these would
be applicable in my scenario).

Thanks.


Claus Ibsen wrote:
> 
> Hi
> 
> Camel has a service interface: org.apache.camel.Service with callbacks for
> start and stop = lifecycle. But I doubt that your processor will receive
> these callback.
> 
> 1)
> If you don't use an anonymous inner class as processor you can just create
> your processor instance once, and then init the XML.
> 
> In the camel route you can pass a reference to your object with
> .processRef() 
> 
> For example in your route builder (if using java):
> Processor myProcessor = new MyProcessor();
> myProcessor.myInit(); // init or do it in the constructor
> 
> from("xxx").processRef(myProcessor).to("seda:yyy")...
> 
> 
> 2)
> If you are using Spring xml for lifecycle management then you can use
> spring to handle this and in the Camel route you can use
> .bean("mySpringBeanId") to invoke you bean where you can do you code as
> the processor did.
> 
> When you use bean then you is able to be less dependent on Camel
> interfaces and in fact you can write it as a POJO with no imports for
> Camel. Camel will invoke your method. 
> 
> from("xxx").bean("mySpringBeanId").to("seda:yyy")...
> 
> See wiki doc
> http://activemq.apache.org/camel/bean.html
> 
> 
> 
> 
> 
> Med venlig hilsen
>  
> Claus Ibsen
> ......................................
> Silverbullet
> Skovsgårdsvænget 21
> 8362 Hørning
> Tlf. +45 2962 7576
> Web: www.silverbullet.dk
> 
> -----Original Message-----
> From: raulvk [mailto:raul.kripalani@atosorigin.com] 
> Sent: 11. september 2008 12:54
> To: camel-user@activemq.apache.org
> Subject: RE: Synchronous/asynchronous bridge
> 
> 
> Ok, got it half-working. Thanks!
> 
> What I have actually done is I have created a private class inside that
> implements Processor, and I am using the .process() DSL instruction to run
> it through it.
> 
> However, the problem I am facing now is that because the response is
> actually returned to a CXF endpoint via ServiceMix, this endpoint expects
> the message within an <jbi:message> ... </jbi:message> envelope.
> 
> Therefore, the XML that I ought to send back is getting a bit more
> complex.
> I am thinking of loading the response XML from a file from the classpath.
> I
> could do this within the process() method, but this would keep loading and
> discarding the XML over and over again, right?
> 
> Do processors have lifecycle methods, such that I can load the XML into
> memory once within an init() method?
> 
> What solution do you suggest to only load the XML from the file into
> memory
> ONCE?
> 
> Thank you!!
> 
> 
> 
> Claus Ibsen wrote:
>> 
>> Hi
>> 
>> BTW: .transform is a new DSL in Camel 1.4. And since you are using
>> ServiceMix it might not be with the latest Camel release.
>> 
>> You can then use .setOutBody instead
>> 
>> 
>> Med venlig hilsen
>>  
>> Claus Ibsen
>> ......................................
>> Silverbullet
>> Skovsgårdsvænget 21
>> 8362 Hørning
>> Tlf. +45 2962 7576
>> Web: www.silverbullet.dk
>> 
>> -----Original Message-----
>> From: Claus Ibsen [mailto:ci@silverbullet.dk] 
>> Sent: 11. september 2008 08:49
>> To: camel-user@activemq.apache.org
>> Subject: RE: Synchronous/asynchronous bridge
>> 
>> Hi
>> 
>> Yes this is possible. The solution is to use a queue where you "split"
>> the
>> request. You can use a JMS queue or a the SEDA queues that Camel has
>> out-of-the-box.
>> http://activemq.apache.org/camel/seda.html
>> 
>> The transform DSL is used for setting the OUT body = the response to the
>> original caller.
>> 
>> 
>> Here is an example of such a scenariou. I have build a unit test to
>> demonstrate this:
>> 
>>     public void testSendAsync() throws Exception {
>>         MockEndpoint mock = getMockEndpoint("mock:result");
>>         mock.expectedBodiesReceived("Hello World");
>> 
>>         Object out = template.requestBody("direct:start", "Hello World");
>>         assertEquals("OK", out);
>> 
>>         assertMockEndpointsSatisfied();
>>     }
>> 
>>     @Override
>>     protected RouteBuilder createRouteBuilder() throws Exception {
>>         return new RouteBuilder() {
>>             public void configure() throws Exception {
>>                 from("direct:start")
>>                     // send it to the seda queue that is async
>>                     .to("seda:next")
>>                     // return a constant response
>>                     .transform(constant("OK"));
>> 
>>                 from("seda:next").to("mock:result");
>>             }
>>         };
>>     }
>> 
>> 
>> 
>> 
>> Med venlig hilsen
>>  
>> Claus Ibsen
>> ......................................
>> Silverbullet
>> Skovsgårdsvænget 21
>> 8362 Hørning
>> Tlf. +45 2962 7576
>> Web: www.silverbullet.dk
>> -----Original Message-----
>> From: raulvk [mailto:raul.kripalani@atosorigin.com] 
>> Sent: 10. september 2008 19:56
>> To: camel-user@activemq.apache.org
>> Subject: Synchronous/asynchronous bridge
>> 
>> 
>> Hi,
>> 
>> I am using Camel embedded in ServiceMix via the servicemix-camel service
>> engine.
>> 
>> I need to implement the following routing scenario:
>> 
>> 
>> HTTP Consumer BC   ---> Camel  --->  Transformation --> HTTP Provider BC
>>              /|\                      |
>>               |______________ |
>> 
>> 
>> Basically, I receive a SOAP request through an HTTP endpoint in
>> ServiceMix
>> and it gets directed to Camel. As soon as Camel receives it, it should
>> immediately return back a fixed response (<Response>OK</Response>), and
>> then
>> it should invoke an XSLT Transformer, and should finally send the
>> transformed message to the HTTP Provider.
>> 
>> I am OK with the bit where I have to use a pipeline, but I don't
>> understand
>> how to return the response half-way through the routing flow.
>> 
>> Could someone help me with this, please?
>> 
>> Thanks a lot!
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19415072.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19432301.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19432640.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: Synchronous/asynchronous bridge

Posted by raulvk <ra...@atosorigin.com>.
Ok, great! Since I am using the Java DSL, I will take the first approach.

Is there a way to pool this object so that there are many instances and
performance is not degraded under high-load circumstances? (I have seen
thread() instructions in the Java DSL, but I am not sure whether these would
be applicable in my scenario).

Thanks.


Claus Ibsen wrote:
> 
> Hi
> 
> Camel has a service interface: org.apache.camel.Service with callbacks for
> start and stop = lifecycle. But I doubt that your processor will receive
> these callback.
> 
> 1)
> If you don't use an anonymous inner class as processor you can just create
> your processor instance once, and then init the XML.
> 
> In the camel route you can pass a reference to your object with
> .processRef() 
> 
> For example in your route builder (if using java):
> Processor myProcessor = new MyProcessor();
> myProcessor.myInit(); // init or do it in the constructor
> 
> from("xxx").processRef(myProcessor).to("seda:yyy")...
> 
> 
> 2)
> If you are using Spring xml for lifecycle management then you can use
> spring to handle this and in the Camel route you can use
> .bean("mySpringBeanId") to invoke you bean where you can do you code as
> the processor did.
> 
> When you use bean then you is able to be less dependent on Camel
> interfaces and in fact you can write it as a POJO with no imports for
> Camel. Camel will invoke your method. 
> 
> from("xxx").bean("mySpringBeanId").to("seda:yyy")...
> 
> See wiki doc
> http://activemq.apache.org/camel/bean.html
> 
> 
> 
> 
> 
> Med venlig hilsen
>  
> Claus Ibsen
> ......................................
> Silverbullet
> Skovsgårdsvænget 21
> 8362 Hørning
> Tlf. +45 2962 7576
> Web: www.silverbullet.dk
> 
> -----Original Message-----
> From: raulvk [mailto:raul.kripalani@atosorigin.com] 
> Sent: 11. september 2008 12:54
> To: camel-user@activemq.apache.org
> Subject: RE: Synchronous/asynchronous bridge
> 
> 
> Ok, got it half-working. Thanks!
> 
> What I have actually done is I have created a private class inside that
> implements Processor, and I am using the .process() DSL instruction to run
> it through it.
> 
> However, the problem I am facing now is that because the response is
> actually returned to a CXF endpoint via ServiceMix, this endpoint expects
> the message within an <jbi:message> ... </jbi:message> envelope.
> 
> Therefore, the XML that I ought to send back is getting a bit more
> complex.
> I am thinking of loading the response XML from a file from the classpath.
> I
> could do this within the process() method, but this would keep loading and
> discarding the XML over and over again, right?
> 
> Do processors have lifecycle methods, such that I can load the XML into
> memory once within an init() method?
> 
> What solution do you suggest to only load the XML from the file into
> memory
> ONCE?
> 
> Thank you!!
> 
> 
> 
> Claus Ibsen wrote:
>> 
>> Hi
>> 
>> BTW: .transform is a new DSL in Camel 1.4. And since you are using
>> ServiceMix it might not be with the latest Camel release.
>> 
>> You can then use .setOutBody instead
>> 
>> 
>> Med venlig hilsen
>>  
>> Claus Ibsen
>> ......................................
>> Silverbullet
>> Skovsgårdsvænget 21
>> 8362 Hørning
>> Tlf. +45 2962 7576
>> Web: www.silverbullet.dk
>> 
>> -----Original Message-----
>> From: Claus Ibsen [mailto:ci@silverbullet.dk] 
>> Sent: 11. september 2008 08:49
>> To: camel-user@activemq.apache.org
>> Subject: RE: Synchronous/asynchronous bridge
>> 
>> Hi
>> 
>> Yes this is possible. The solution is to use a queue where you "split"
>> the
>> request. You can use a JMS queue or a the SEDA queues that Camel has
>> out-of-the-box.
>> http://activemq.apache.org/camel/seda.html
>> 
>> The transform DSL is used for setting the OUT body = the response to the
>> original caller.
>> 
>> 
>> Here is an example of such a scenariou. I have build a unit test to
>> demonstrate this:
>> 
>>     public void testSendAsync() throws Exception {
>>         MockEndpoint mock = getMockEndpoint("mock:result");
>>         mock.expectedBodiesReceived("Hello World");
>> 
>>         Object out = template.requestBody("direct:start", "Hello World");
>>         assertEquals("OK", out);
>> 
>>         assertMockEndpointsSatisfied();
>>     }
>> 
>>     @Override
>>     protected RouteBuilder createRouteBuilder() throws Exception {
>>         return new RouteBuilder() {
>>             public void configure() throws Exception {
>>                 from("direct:start")
>>                     // send it to the seda queue that is async
>>                     .to("seda:next")
>>                     // return a constant response
>>                     .transform(constant("OK"));
>> 
>>                 from("seda:next").to("mock:result");
>>             }
>>         };
>>     }
>> 
>> 
>> 
>> 
>> Med venlig hilsen
>>  
>> Claus Ibsen
>> ......................................
>> Silverbullet
>> Skovsgårdsvænget 21
>> 8362 Hørning
>> Tlf. +45 2962 7576
>> Web: www.silverbullet.dk
>> -----Original Message-----
>> From: raulvk [mailto:raul.kripalani@atosorigin.com] 
>> Sent: 10. september 2008 19:56
>> To: camel-user@activemq.apache.org
>> Subject: Synchronous/asynchronous bridge
>> 
>> 
>> Hi,
>> 
>> I am using Camel embedded in ServiceMix via the servicemix-camel service
>> engine.
>> 
>> I need to implement the following routing scenario:
>> 
>> 
>> HTTP Consumer BC   ---> Camel  --->  Transformation --> HTTP Provider BC
>>              /|\                      |
>>               |______________ |
>> 
>> 
>> Basically, I receive a SOAP request through an HTTP endpoint in
>> ServiceMix
>> and it gets directed to Camel. As soon as Camel receives it, it should
>> immediately return back a fixed response (<Response>OK</Response>), and
>> then
>> it should invoke an XSLT Transformer, and should finally send the
>> transformed message to the HTTP Provider.
>> 
>> I am OK with the bit where I have to use a pipeline, but I don't
>> understand
>> how to return the response half-way through the routing flow.
>> 
>> Could someone help me with this, please?
>> 
>> Thanks a lot!
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19415072.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19432301.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19432640.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: Synchronous/asynchronous bridge

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

Camel has a service interface: org.apache.camel.Service with callbacks for start and stop = lifecycle. But I doubt that your processor will receive these callback.

1)
If you don't use an anonymous inner class as processor you can just create your processor instance once, and then init the XML.

In the camel route you can pass a reference to your object with .processRef() 

For example in your route builder (if using java):
Processor myProcessor = new MyProcessor();
myProcessor.myInit(); // init or do it in the constructor

from("xxx").processRef(myProcessor).to("seda:yyy")...


2)
If you are using Spring xml for lifecycle management then you can use spring to handle this and in the Camel route you can use .bean("mySpringBeanId") to invoke you bean where you can do you code as the processor did.

When you use bean then you is able to be less dependent on Camel interfaces and in fact you can write it as a POJO with no imports for Camel. Camel will invoke your method. 

from("xxx").bean("mySpringBeanId").to("seda:yyy")...

See wiki doc
http://activemq.apache.org/camel/bean.html





Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: raulvk [mailto:raul.kripalani@atosorigin.com] 
Sent: 11. september 2008 12:54
To: camel-user@activemq.apache.org
Subject: RE: Synchronous/asynchronous bridge


Ok, got it half-working. Thanks!

What I have actually done is I have created a private class inside that
implements Processor, and I am using the .process() DSL instruction to run
it through it.

However, the problem I am facing now is that because the response is
actually returned to a CXF endpoint via ServiceMix, this endpoint expects
the message within an <jbi:message> ... </jbi:message> envelope.

Therefore, the XML that I ought to send back is getting a bit more complex.
I am thinking of loading the response XML from a file from the classpath. I
could do this within the process() method, but this would keep loading and
discarding the XML over and over again, right?

Do processors have lifecycle methods, such that I can load the XML into
memory once within an init() method?

What solution do you suggest to only load the XML from the file into memory
ONCE?

Thank you!!



Claus Ibsen wrote:
> 
> Hi
> 
> BTW: .transform is a new DSL in Camel 1.4. And since you are using
> ServiceMix it might not be with the latest Camel release.
> 
> You can then use .setOutBody instead
> 
> 
> Med venlig hilsen
>  
> Claus Ibsen
> ......................................
> Silverbullet
> Skovsgårdsvænget 21
> 8362 Hørning
> Tlf. +45 2962 7576
> Web: www.silverbullet.dk
> 
> -----Original Message-----
> From: Claus Ibsen [mailto:ci@silverbullet.dk] 
> Sent: 11. september 2008 08:49
> To: camel-user@activemq.apache.org
> Subject: RE: Synchronous/asynchronous bridge
> 
> Hi
> 
> Yes this is possible. The solution is to use a queue where you "split" the
> request. You can use a JMS queue or a the SEDA queues that Camel has
> out-of-the-box.
> http://activemq.apache.org/camel/seda.html
> 
> The transform DSL is used for setting the OUT body = the response to the
> original caller.
> 
> 
> Here is an example of such a scenariou. I have build a unit test to
> demonstrate this:
> 
>     public void testSendAsync() throws Exception {
>         MockEndpoint mock = getMockEndpoint("mock:result");
>         mock.expectedBodiesReceived("Hello World");
> 
>         Object out = template.requestBody("direct:start", "Hello World");
>         assertEquals("OK", out);
> 
>         assertMockEndpointsSatisfied();
>     }
> 
>     @Override
>     protected RouteBuilder createRouteBuilder() throws Exception {
>         return new RouteBuilder() {
>             public void configure() throws Exception {
>                 from("direct:start")
>                     // send it to the seda queue that is async
>                     .to("seda:next")
>                     // return a constant response
>                     .transform(constant("OK"));
> 
>                 from("seda:next").to("mock:result");
>             }
>         };
>     }
> 
> 
> 
> 
> Med venlig hilsen
>  
> Claus Ibsen
> ......................................
> Silverbullet
> Skovsgårdsvænget 21
> 8362 Hørning
> Tlf. +45 2962 7576
> Web: www.silverbullet.dk
> -----Original Message-----
> From: raulvk [mailto:raul.kripalani@atosorigin.com] 
> Sent: 10. september 2008 19:56
> To: camel-user@activemq.apache.org
> Subject: Synchronous/asynchronous bridge
> 
> 
> Hi,
> 
> I am using Camel embedded in ServiceMix via the servicemix-camel service
> engine.
> 
> I need to implement the following routing scenario:
> 
> 
> HTTP Consumer BC   ---> Camel  --->  Transformation --> HTTP Provider BC
>              /|\                      |
>               |______________ |
> 
> 
> Basically, I receive a SOAP request through an HTTP endpoint in ServiceMix
> and it gets directed to Camel. As soon as Camel receives it, it should
> immediately return back a fixed response (<Response>OK</Response>), and
> then
> it should invoke an XSLT Transformer, and should finally send the
> transformed message to the HTTP Provider.
> 
> I am OK with the bit where I have to use a pipeline, but I don't
> understand
> how to return the response half-way through the routing flow.
> 
> Could someone help me with this, please?
> 
> Thanks a lot!
> 
> -- 
> View this message in context:
> http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19415072.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19432301.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: Synchronous/asynchronous bridge

Posted by raulvk <ra...@atosorigin.com>.
Ok, got it half-working. Thanks!

What I have actually done is I have created a private class inside that
implements Processor, and I am using the .process() DSL instruction to run
it through it.

However, the problem I am facing now is that because the response is
actually returned to a CXF endpoint via ServiceMix, this endpoint expects
the message within an <jbi:message> ... </jbi:message> envelope.

Therefore, the XML that I ought to send back is getting a bit more complex.
I am thinking of loading the response XML from a file from the classpath. I
could do this within the process() method, but this would keep loading and
discarding the XML over and over again, right?

Do processors have lifecycle methods, such that I can load the XML into
memory once within an init() method?

What solution do you suggest to only load the XML from the file into memory
ONCE?

Thank you!!



Claus Ibsen wrote:
> 
> Hi
> 
> BTW: .transform is a new DSL in Camel 1.4. And since you are using
> ServiceMix it might not be with the latest Camel release.
> 
> You can then use .setOutBody instead
> 
> 
> Med venlig hilsen
>  
> Claus Ibsen
> ......................................
> Silverbullet
> Skovsgårdsvænget 21
> 8362 Hørning
> Tlf. +45 2962 7576
> Web: www.silverbullet.dk
> 
> -----Original Message-----
> From: Claus Ibsen [mailto:ci@silverbullet.dk] 
> Sent: 11. september 2008 08:49
> To: camel-user@activemq.apache.org
> Subject: RE: Synchronous/asynchronous bridge
> 
> Hi
> 
> Yes this is possible. The solution is to use a queue where you "split" the
> request. You can use a JMS queue or a the SEDA queues that Camel has
> out-of-the-box.
> http://activemq.apache.org/camel/seda.html
> 
> The transform DSL is used for setting the OUT body = the response to the
> original caller.
> 
> 
> Here is an example of such a scenariou. I have build a unit test to
> demonstrate this:
> 
>     public void testSendAsync() throws Exception {
>         MockEndpoint mock = getMockEndpoint("mock:result");
>         mock.expectedBodiesReceived("Hello World");
> 
>         Object out = template.requestBody("direct:start", "Hello World");
>         assertEquals("OK", out);
> 
>         assertMockEndpointsSatisfied();
>     }
> 
>     @Override
>     protected RouteBuilder createRouteBuilder() throws Exception {
>         return new RouteBuilder() {
>             public void configure() throws Exception {
>                 from("direct:start")
>                     // send it to the seda queue that is async
>                     .to("seda:next")
>                     // return a constant response
>                     .transform(constant("OK"));
> 
>                 from("seda:next").to("mock:result");
>             }
>         };
>     }
> 
> 
> 
> 
> Med venlig hilsen
>  
> Claus Ibsen
> ......................................
> Silverbullet
> Skovsgårdsvænget 21
> 8362 Hørning
> Tlf. +45 2962 7576
> Web: www.silverbullet.dk
> -----Original Message-----
> From: raulvk [mailto:raul.kripalani@atosorigin.com] 
> Sent: 10. september 2008 19:56
> To: camel-user@activemq.apache.org
> Subject: Synchronous/asynchronous bridge
> 
> 
> Hi,
> 
> I am using Camel embedded in ServiceMix via the servicemix-camel service
> engine.
> 
> I need to implement the following routing scenario:
> 
> 
> HTTP Consumer BC   ---> Camel  --->  Transformation --> HTTP Provider BC
>              /|\                      |
>               |______________ |
> 
> 
> Basically, I receive a SOAP request through an HTTP endpoint in ServiceMix
> and it gets directed to Camel. As soon as Camel receives it, it should
> immediately return back a fixed response (<Response>OK</Response>), and
> then
> it should invoke an XSLT Transformer, and should finally send the
> transformed message to the HTTP Provider.
> 
> I am OK with the bit where I have to use a pipeline, but I don't
> understand
> how to return the response half-way through the routing flow.
> 
> Could someone help me with this, please?
> 
> Thanks a lot!
> 
> -- 
> View this message in context:
> http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19415072.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19432301.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: Synchronous/asynchronous bridge

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

BTW: .transform is a new DSL in Camel 1.4. And since you are using ServiceMix it might not be with the latest Camel release.

You can then use .setOutBody instead


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: Claus Ibsen [mailto:ci@silverbullet.dk] 
Sent: 11. september 2008 08:49
To: camel-user@activemq.apache.org
Subject: RE: Synchronous/asynchronous bridge

Hi

Yes this is possible. The solution is to use a queue where you "split" the request. You can use a JMS queue or a the SEDA queues that Camel has out-of-the-box.
http://activemq.apache.org/camel/seda.html

The transform DSL is used for setting the OUT body = the response to the original caller.


Here is an example of such a scenariou. I have build a unit test to demonstrate this:

    public void testSendAsync() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedBodiesReceived("Hello World");

        Object out = template.requestBody("direct:start", "Hello World");
        assertEquals("OK", out);

        assertMockEndpointsSatisfied();
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() throws Exception {
                from("direct:start")
                    // send it to the seda queue that is async
                    .to("seda:next")
                    // return a constant response
                    .transform(constant("OK"));

                from("seda:next").to("mock:result");
            }
        };
    }




Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: raulvk [mailto:raul.kripalani@atosorigin.com] 
Sent: 10. september 2008 19:56
To: camel-user@activemq.apache.org
Subject: Synchronous/asynchronous bridge


Hi,

I am using Camel embedded in ServiceMix via the servicemix-camel service
engine.

I need to implement the following routing scenario:


HTTP Consumer BC   ---> Camel  --->  Transformation --> HTTP Provider BC
             /|\                      |
              |______________ |


Basically, I receive a SOAP request through an HTTP endpoint in ServiceMix
and it gets directed to Camel. As soon as Camel receives it, it should
immediately return back a fixed response (<Response>OK</Response>), and then
it should invoke an XSLT Transformer, and should finally send the
transformed message to the HTTP Provider.

I am OK with the bit where I have to use a pipeline, but I don't understand
how to return the response half-way through the routing flow.

Could someone help me with this, please?

Thanks a lot!

-- 
View this message in context: http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19415072.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: Synchronous/asynchronous bridge

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

Yes this is possible. The solution is to use a queue where you "split" the request. You can use a JMS queue or a the SEDA queues that Camel has out-of-the-box.
http://activemq.apache.org/camel/seda.html

The transform DSL is used for setting the OUT body = the response to the original caller.


Here is an example of such a scenariou. I have build a unit test to demonstrate this:

    public void testSendAsync() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedBodiesReceived("Hello World");

        Object out = template.requestBody("direct:start", "Hello World");
        assertEquals("OK", out);

        assertMockEndpointsSatisfied();
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() throws Exception {
                from("direct:start")
                    // send it to the seda queue that is async
                    .to("seda:next")
                    // return a constant response
                    .transform(constant("OK"));

                from("seda:next").to("mock:result");
            }
        };
    }




Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: raulvk [mailto:raul.kripalani@atosorigin.com] 
Sent: 10. september 2008 19:56
To: camel-user@activemq.apache.org
Subject: Synchronous/asynchronous bridge


Hi,

I am using Camel embedded in ServiceMix via the servicemix-camel service
engine.

I need to implement the following routing scenario:


HTTP Consumer BC   ---> Camel  --->  Transformation --> HTTP Provider BC
             /|\                      |
              |______________ |


Basically, I receive a SOAP request through an HTTP endpoint in ServiceMix
and it gets directed to Camel. As soon as Camel receives it, it should
immediately return back a fixed response (<Response>OK</Response>), and then
it should invoke an XSLT Transformer, and should finally send the
transformed message to the HTTP Provider.

I am OK with the bit where I have to use a pipeline, but I don't understand
how to return the response half-way through the routing flow.

Could someone help me with this, please?

Thanks a lot!

-- 
View this message in context: http://www.nabble.com/Synchronous-asynchronous-bridge-tp19415072s22882p19415072.html
Sent from the Camel - Users mailing list archive at Nabble.com.