You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Tarun Kumar <ag...@gmail.com> on 2013/04/09 04:45:13 UTC

ProducerTemplate and direct:start in camel

My camel route is :

from("direct:start")
.to("http://myhost/mypath");

I used :

ProducerTemplate template;
template.sendBody("direct:start", "This is a test message");

to send the exchange. I am getting following exception:

No consumers available on endpoint: Endpoint[direct://start].

How can i receive the same exchange in direct:start endpoint?


Tarun

Re: ProducerTemplate and direct:start in camel

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi Tarun,

from you description


> I have written one JAX-RS service which when invoked creates CamelContext,
> adds this route to CamelContext, Create ProducerTemplate, calls
> pt.sendBody() method and then starts CamelContext.

you start the CamelContext AFTER you use the ProducerTemplate but you have to start it BEFORE you can use it. As the Context is not started there is no route!

BR
Maruan Sahyoun

Am 09.04.2013 um 06:30 schrieb Tarun Kumar <ag...@gmail.com>:

> "Ok, first thing is you need to start your context (which starts the routes)
> before you can use a producer template to send a message to it. Starting
> the context is what creates and publishes the endpoints so that they can
> receive messages. If the context isn't started there is no "direct:start"
> endpoint deployed which is the error you are getting."
> 
> So, you mean i should create ProducerTemplate in configure method of route?
> Can you please give me code sample for that?
> 
> 
> From an architectural point of view, starting a new context on every web
> request probably isn't the best idea. It looks like you are developing a
> web proxy (receive on one endpoint and send to another web service) so
> might I suggest that instead of hosting a camel route inside a JAX-RS
> service you have a camel app that has a JAX-RS endpoint as the entry? That
> way you have one route that is reused many times. In your current approach,
> how are you stopping the contexts/routes and cleaning up resources?
> 
> Actually, i am not creating webproxy. That was just an example. I am using
> camel for orchestration. So, when rest based service is hit, i want to
> invoke another service, followed by one more service and return the final
> response to the user.
> 
> basically,
> 
> from(direct:start).to("rest-serviceA").process().to("rest-serviceB")
> 
> Main problem i am facing is, i am not able to start the route i.e.
> from(direct:start) is not executing. I read somewhere that for that i will
> need to use producerTemplate. But, when i use that , i am getting No
> consumers available on endpoint: Endpoint[direct://start]. So, Should i
> start ProducerTemplate in route configure method? How can i consume
> exchange of ProducerTemplate?
> 
> Really appreciate your help! Thanks!
> 
> Tarun
> 
> 
> On Tue, Apr 9, 2013 at 8:33 AM, Chris Geer <ch...@cxtsoftware.com> wrote:
> 
>> On Mon, Apr 8, 2013 at 7:56 PM, Tarun Kumar <agrawal.tarun23@gmail.com
>>> wrote:
>> 
>>> Here's what i am doing:
>>> 
>>> I have written one JAX-RS service which when invoked creates
>> CamelContext,
>>> adds this route to CamelContext, Create ProducerTemplate, calls
>>> pt.sendBody() method and then starts CamelContext.
>>> 
>> 
>> 
>> 
>> From an architectural point of view, starting a new context on every web
>> request probably isn't the best idea. It looks like you are developing a
>> web proxy (receive on one endpoint and send to another web service) so
>> might I suggest that instead of hosting a camel route inside a JAX-RS
>> service you have a camel app that has a JAX-RS endpoint as the entry? That
>> way you have one route that is reused many times. In your current approach,
>> how are you stopping the contexts/routes and cleaning up resources?
>> 
>>> 
>>> Tarun
>>> 
>>> 
>>> On Tue, Apr 9, 2013 at 8:19 AM, Chris Geer <ch...@cxtsoftware.com>
>> wrote:
>>> 
>>>> On Mon, Apr 8, 2013 at 7:45 PM, Tarun Kumar <agrawal.tarun23@gmail.com
>>>>> wrote:
>>>> 
>>>>> My camel route is :
>>>>> 
>>>>> from("direct:start")
>>>>> .to("http://myhost/mypath");
>>>>> 
>>>>> I used :
>>>>> 
>>>>> ProducerTemplate template;
>>>>> template.sendBody("direct:start", "This is a test message");
>>>>> 
>>>>> to send the exchange. I am getting following exception:
>>>>> 
>>>>> No consumers available on endpoint: Endpoint[direct://start].
>>>>> 
>>>>> How can i receive the same exchange in direct:start endpoint?
>>>>> 
>>>> 
>>>> How are you running your application? Standalone camel application from
>>>> main() or OSGI bundle? Assuming it's a stand alone application did you
>>> make
>>>> sure and start your context?
>>>> 
>>>>> 
>>>>> 
>>>>> Tarun
>>>>> 
>>>> 
>>> 
>> 


Re: ProducerTemplate and direct:start in camel

Posted by Chris Geer <ch...@cxtsoftware.com>.
On Mon, Apr 8, 2013 at 9:30 PM, Tarun Kumar <ag...@gmail.com>wrote:

> "Ok, first thing is you need to start your context (which starts the
> routes)
> before you can use a producer template to send a message to it. Starting
> the context is what creates and publishes the endpoints so that they can
> receive messages. If the context isn't started there is no "direct:start"
> endpoint deployed which is the error you are getting."
>
> So, you mean i should create ProducerTemplate in configure method of route?
> Can you please give me code sample for that?
>

No, that's not what I meant. All you need to do is reorder your method
calls.

1) Create Context
2) Add Route
3) Create Template
4) Start Context (you might have to pause after this to let the context
spin up)
5) Send Message (i.e. pt.sendBody)

Here is an example [1]. It's not an exact match but it shows the concept
where steps 1-4 are done in the constructor, step 5 is done on the
invocation.

[1] http://camel.apache.org/tutorial-example-reportincident-part3.html

>
>
> From an architectural point of view, starting a new context on every web
> request probably isn't the best idea. It looks like you are developing a
> web proxy (receive on one endpoint and send to another web service) so
> might I suggest that instead of hosting a camel route inside a JAX-RS
> service you have a camel app that has a JAX-RS endpoint as the entry? That
> way you have one route that is reused many times. In your current approach,
> how are you stopping the contexts/routes and cleaning up resources?
>
> Actually, i am not creating webproxy. That was just an example. I am using
> camel for orchestration. So, when rest based service is hit, i want to
> invoke another service, followed by one more service and return the final
> response to the user.
>
> basically,
>
> from(direct:start).to("rest-serviceA").process().to("rest-serviceB")
>

I still think you might want to consider the alternative of:

from("jetty:http://...").to("rest-serviceA").process().to("rest-serviceB")

or

from("cxfrs:...").to("rest-serviceA").process().to("rest-serviceB")

Do the whole thing in the camel route.

>
> Main problem i am facing is, i am not able to start the route i.e.
> from(direct:start) is not executing. I read somewhere that for that i will
> need to use producerTemplate. But, when i use that , i am getting No
> consumers available on endpoint: Endpoint[direct://start]. So, Should i
> start ProducerTemplate in route configure method? How can i consume
> exchange of ProducerTemplate?
>
> Really appreciate your help! Thanks!
>
> Tarun
>
>
> On Tue, Apr 9, 2013 at 8:33 AM, Chris Geer <ch...@cxtsoftware.com> wrote:
>
> > On Mon, Apr 8, 2013 at 7:56 PM, Tarun Kumar <agrawal.tarun23@gmail.com
> > >wrote:
> >
> > > Here's what i am doing:
> > >
> > > I have written one JAX-RS service which when invoked creates
> > CamelContext,
> > > adds this route to CamelContext, Create ProducerTemplate, calls
> > > pt.sendBody() method and then starts CamelContext.
> > >
> >
> >
> >
> > From an architectural point of view, starting a new context on every web
> > request probably isn't the best idea. It looks like you are developing a
> > web proxy (receive on one endpoint and send to another web service) so
> > might I suggest that instead of hosting a camel route inside a JAX-RS
> > service you have a camel app that has a JAX-RS endpoint as the entry?
> That
> > way you have one route that is reused many times. In your current
> approach,
> > how are you stopping the contexts/routes and cleaning up resources?
> >
> > >
> > > Tarun
> > >
> > >
> > > On Tue, Apr 9, 2013 at 8:19 AM, Chris Geer <ch...@cxtsoftware.com>
> > wrote:
> > >
> > > > On Mon, Apr 8, 2013 at 7:45 PM, Tarun Kumar <
> agrawal.tarun23@gmail.com
> > > > >wrote:
> > > >
> > > > > My camel route is :
> > > > >
> > > > > from("direct:start")
> > > > > .to("http://myhost/mypath");
> > > > >
> > > > > I used :
> > > > >
> > > > > ProducerTemplate template;
> > > > > template.sendBody("direct:start", "This is a test message");
> > > > >
> > > > > to send the exchange. I am getting following exception:
> > > > >
> > > > > No consumers available on endpoint: Endpoint[direct://start].
> > > > >
> > > > > How can i receive the same exchange in direct:start endpoint?
> > > > >
> > > >
> > > > How are you running your application? Standalone camel application
> from
> > > > main() or OSGI bundle? Assuming it's a stand alone application did
> you
> > > make
> > > > sure and start your context?
> > > >
> > > > >
> > > > >
> > > > > Tarun
> > > > >
> > > >
> > >
> >
>

Re: ProducerTemplate and direct:start in camel

Posted by Tarun Kumar <ag...@gmail.com>.
"Ok, first thing is you need to start your context (which starts the routes)
before you can use a producer template to send a message to it. Starting
the context is what creates and publishes the endpoints so that they can
receive messages. If the context isn't started there is no "direct:start"
endpoint deployed which is the error you are getting."

So, you mean i should create ProducerTemplate in configure method of route?
Can you please give me code sample for that?


>From an architectural point of view, starting a new context on every web
request probably isn't the best idea. It looks like you are developing a
web proxy (receive on one endpoint and send to another web service) so
might I suggest that instead of hosting a camel route inside a JAX-RS
service you have a camel app that has a JAX-RS endpoint as the entry? That
way you have one route that is reused many times. In your current approach,
how are you stopping the contexts/routes and cleaning up resources?

Actually, i am not creating webproxy. That was just an example. I am using
camel for orchestration. So, when rest based service is hit, i want to
invoke another service, followed by one more service and return the final
response to the user.

basically,

from(direct:start).to("rest-serviceA").process().to("rest-serviceB")

Main problem i am facing is, i am not able to start the route i.e.
from(direct:start) is not executing. I read somewhere that for that i will
need to use producerTemplate. But, when i use that , i am getting No
consumers available on endpoint: Endpoint[direct://start]. So, Should i
start ProducerTemplate in route configure method? How can i consume
exchange of ProducerTemplate?

Really appreciate your help! Thanks!

Tarun


On Tue, Apr 9, 2013 at 8:33 AM, Chris Geer <ch...@cxtsoftware.com> wrote:

> On Mon, Apr 8, 2013 at 7:56 PM, Tarun Kumar <agrawal.tarun23@gmail.com
> >wrote:
>
> > Here's what i am doing:
> >
> > I have written one JAX-RS service which when invoked creates
> CamelContext,
> > adds this route to CamelContext, Create ProducerTemplate, calls
> > pt.sendBody() method and then starts CamelContext.
> >
>
>
>
> From an architectural point of view, starting a new context on every web
> request probably isn't the best idea. It looks like you are developing a
> web proxy (receive on one endpoint and send to another web service) so
> might I suggest that instead of hosting a camel route inside a JAX-RS
> service you have a camel app that has a JAX-RS endpoint as the entry? That
> way you have one route that is reused many times. In your current approach,
> how are you stopping the contexts/routes and cleaning up resources?
>
> >
> > Tarun
> >
> >
> > On Tue, Apr 9, 2013 at 8:19 AM, Chris Geer <ch...@cxtsoftware.com>
> wrote:
> >
> > > On Mon, Apr 8, 2013 at 7:45 PM, Tarun Kumar <agrawal.tarun23@gmail.com
> > > >wrote:
> > >
> > > > My camel route is :
> > > >
> > > > from("direct:start")
> > > > .to("http://myhost/mypath");
> > > >
> > > > I used :
> > > >
> > > > ProducerTemplate template;
> > > > template.sendBody("direct:start", "This is a test message");
> > > >
> > > > to send the exchange. I am getting following exception:
> > > >
> > > > No consumers available on endpoint: Endpoint[direct://start].
> > > >
> > > > How can i receive the same exchange in direct:start endpoint?
> > > >
> > >
> > > How are you running your application? Standalone camel application from
> > > main() or OSGI bundle? Assuming it's a stand alone application did you
> > make
> > > sure and start your context?
> > >
> > > >
> > > >
> > > > Tarun
> > > >
> > >
> >
>

Re: ProducerTemplate and direct:start in camel

Posted by Chris Geer <ch...@cxtsoftware.com>.
On Mon, Apr 8, 2013 at 7:56 PM, Tarun Kumar <ag...@gmail.com>wrote:

> Here's what i am doing:
>
> I have written one JAX-RS service which when invoked creates CamelContext,
> adds this route to CamelContext, Create ProducerTemplate, calls
> pt.sendBody() method and then starts CamelContext.
>

Ok, first thing is you need to start your context (which starts the routes)
before you can use a producer template to send a message to it. Starting
the context is what creates and publishes the endpoints so that they can
receive messages. If the context isn't started there is no "direct:start"
endpoint deployed which is the error you are getting.

>From an architectural point of view, starting a new context on every web
request probably isn't the best idea. It looks like you are developing a
web proxy (receive on one endpoint and send to another web service) so
might I suggest that instead of hosting a camel route inside a JAX-RS
service you have a camel app that has a JAX-RS endpoint as the entry? That
way you have one route that is reused many times. In your current approach,
how are you stopping the contexts/routes and cleaning up resources?

>
> Tarun
>
>
> On Tue, Apr 9, 2013 at 8:19 AM, Chris Geer <ch...@cxtsoftware.com> wrote:
>
> > On Mon, Apr 8, 2013 at 7:45 PM, Tarun Kumar <agrawal.tarun23@gmail.com
> > >wrote:
> >
> > > My camel route is :
> > >
> > > from("direct:start")
> > > .to("http://myhost/mypath");
> > >
> > > I used :
> > >
> > > ProducerTemplate template;
> > > template.sendBody("direct:start", "This is a test message");
> > >
> > > to send the exchange. I am getting following exception:
> > >
> > > No consumers available on endpoint: Endpoint[direct://start].
> > >
> > > How can i receive the same exchange in direct:start endpoint?
> > >
> >
> > How are you running your application? Standalone camel application from
> > main() or OSGI bundle? Assuming it's a stand alone application did you
> make
> > sure and start your context?
> >
> > >
> > >
> > > Tarun
> > >
> >
>

Re: ProducerTemplate and direct:start in camel

Posted by Tarun Kumar <ag...@gmail.com>.
Here's what i am doing:

I have written one JAX-RS service which when invoked creates CamelContext,
adds this route to CamelContext, Create ProducerTemplate, calls
pt.sendBody() method and then starts CamelContext.

Tarun


On Tue, Apr 9, 2013 at 8:19 AM, Chris Geer <ch...@cxtsoftware.com> wrote:

> On Mon, Apr 8, 2013 at 7:45 PM, Tarun Kumar <agrawal.tarun23@gmail.com
> >wrote:
>
> > My camel route is :
> >
> > from("direct:start")
> > .to("http://myhost/mypath");
> >
> > I used :
> >
> > ProducerTemplate template;
> > template.sendBody("direct:start", "This is a test message");
> >
> > to send the exchange. I am getting following exception:
> >
> > No consumers available on endpoint: Endpoint[direct://start].
> >
> > How can i receive the same exchange in direct:start endpoint?
> >
>
> How are you running your application? Standalone camel application from
> main() or OSGI bundle? Assuming it's a stand alone application did you make
> sure and start your context?
>
> >
> >
> > Tarun
> >
>

Re: ProducerTemplate and direct:start in camel

Posted by Chris Geer <ch...@cxtsoftware.com>.
On Mon, Apr 8, 2013 at 7:45 PM, Tarun Kumar <ag...@gmail.com>wrote:

> My camel route is :
>
> from("direct:start")
> .to("http://myhost/mypath");
>
> I used :
>
> ProducerTemplate template;
> template.sendBody("direct:start", "This is a test message");
>
> to send the exchange. I am getting following exception:
>
> No consumers available on endpoint: Endpoint[direct://start].
>
> How can i receive the same exchange in direct:start endpoint?
>

How are you running your application? Standalone camel application from
main() or OSGI bundle? Assuming it's a stand alone application did you make
sure and start your context?

>
>
> Tarun
>