You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Chris <cw...@gmail.com> on 2013/10/04 19:28:52 UTC

How to programmatically find next downstream endpoint in a route.

Hello,

I implemented a bean whose method accepts an exchange with a single 
message, then generates multiple messages intended for the next endpoint 
down-stream, along the lines of this:

http://camel.apache.org/how-do-i-write-a-custom-processor-which-sends-multiple-messages.html


However, I'd like to avoid having to explicitly configure the endpoint 
in the bean's ProducerTemplate if it can be found in the route definition.

In other words, if I have:

from("direct:start")
.enrich("bean:MyBean")
.to("mock:result");  <<< this should be sufficient to indicate producer 
target URI.

...and MyBean is:

public MyBean {
   protected ProducerTemplate producer;
   public void businessLogic(Exchange exchange) {
       if (producer == null) {
           producer = exchange.createProducerTemplate();
           producer.setDefaultEndpointUri("mock:result"); <<< Why should 
I have to do this?  I just want it to go to the next down-stream 
endpoint in the pipeline, already defined in the route!!<<<<
       }
       [...bla, bla, bla...]
       while (hasStuffToSend) {
           producer.setBody(stuff[i]);
       }
   }
}



Re: How to programmatically find next downstream endpoint in a route.

Posted by James Carman <ja...@carmanconsulting.com>.
The next step in the route may not be an endpoint, so it's not
"addressable" in that way.

On Mon, Oct 7, 2013 at 12:02 PM, Chris <cw...@gmail.com> wrote:
> James, thanks for the suggestion - I'll try that, however, I would still
> like to know if/how a given endpoint can programmtically find the next
> down-stream endpoint in a route...
>
>
> On 10/4/2013 1:38 PM, James Carman wrote:
>>
>> Does a splitter not work for you in this case?
>>
>> On Fri, Oct 4, 2013 at 1:28 PM, Chris <cw...@gmail.com> wrote:
>>>
>>> Hello,
>>>
>>> I implemented a bean whose method accepts an exchange with a single
>>> message,
>>> then generates multiple messages intended for the next endpoint
>>> down-stream,
>>> along the lines of this:
>>>
>>>
>>> http://camel.apache.org/how-do-i-write-a-custom-processor-which-sends-multiple-messages.html
>>>
>>>
>>> However, I'd like to avoid having to explicitly configure the endpoint in
>>> the bean's ProducerTemplate if it can be found in the route definition.
>>>
>>> In other words, if I have:
>>>
>>> from("direct:start")
>>> .enrich("bean:MyBean")
>>> .to("mock:result");  <<< this should be sufficient to indicate producer
>>> target URI.
>>>
>>> ...and MyBean is:
>>>
>>> public MyBean {
>>>    protected ProducerTemplate producer;
>>>    public void businessLogic(Exchange exchange) {
>>>        if (producer == null) {
>>>            producer = exchange.createProducerTemplate();
>>>            producer.setDefaultEndpointUri("mock:result"); <<< Why should
>>> I
>>> have to do this?  I just want it to go to the next down-stream endpoint
>>> in
>>> the pipeline, already defined in the route!!<<<<
>>>        }
>>>        [...bla, bla, bla...]
>>>        while (hasStuffToSend) {
>>>            producer.setBody(stuff[i]);
>>>        }
>>>    }
>>> }
>>>
>>>
>

Re: How to programmatically find next downstream endpoint in a route.

Posted by Chris <cw...@gmail.com>.
James, thanks for the suggestion - I'll try that, however, I would still 
like to know if/how a given endpoint can programmtically find the next 
down-stream endpoint in a route...

On 10/4/2013 1:38 PM, James Carman wrote:
> Does a splitter not work for you in this case?
>
> On Fri, Oct 4, 2013 at 1:28 PM, Chris <cw...@gmail.com> wrote:
>> Hello,
>>
>> I implemented a bean whose method accepts an exchange with a single message,
>> then generates multiple messages intended for the next endpoint down-stream,
>> along the lines of this:
>>
>> http://camel.apache.org/how-do-i-write-a-custom-processor-which-sends-multiple-messages.html
>>
>>
>> However, I'd like to avoid having to explicitly configure the endpoint in
>> the bean's ProducerTemplate if it can be found in the route definition.
>>
>> In other words, if I have:
>>
>> from("direct:start")
>> .enrich("bean:MyBean")
>> .to("mock:result");  <<< this should be sufficient to indicate producer
>> target URI.
>>
>> ...and MyBean is:
>>
>> public MyBean {
>>    protected ProducerTemplate producer;
>>    public void businessLogic(Exchange exchange) {
>>        if (producer == null) {
>>            producer = exchange.createProducerTemplate();
>>            producer.setDefaultEndpointUri("mock:result"); <<< Why should I
>> have to do this?  I just want it to go to the next down-stream endpoint in
>> the pipeline, already defined in the route!!<<<<
>>        }
>>        [...bla, bla, bla...]
>>        while (hasStuffToSend) {
>>            producer.setBody(stuff[i]);
>>        }
>>    }
>> }
>>
>>

Re: How to programmatically find next downstream endpoint in a route.

Posted by James Carman <ja...@carmanconsulting.com>.
Does a splitter not work for you in this case?

On Fri, Oct 4, 2013 at 1:28 PM, Chris <cw...@gmail.com> wrote:
> Hello,
>
> I implemented a bean whose method accepts an exchange with a single message,
> then generates multiple messages intended for the next endpoint down-stream,
> along the lines of this:
>
> http://camel.apache.org/how-do-i-write-a-custom-processor-which-sends-multiple-messages.html
>
>
> However, I'd like to avoid having to explicitly configure the endpoint in
> the bean's ProducerTemplate if it can be found in the route definition.
>
> In other words, if I have:
>
> from("direct:start")
> .enrich("bean:MyBean")
> .to("mock:result");  <<< this should be sufficient to indicate producer
> target URI.
>
> ...and MyBean is:
>
> public MyBean {
>   protected ProducerTemplate producer;
>   public void businessLogic(Exchange exchange) {
>       if (producer == null) {
>           producer = exchange.createProducerTemplate();
>           producer.setDefaultEndpointUri("mock:result"); <<< Why should I
> have to do this?  I just want it to go to the next down-stream endpoint in
> the pipeline, already defined in the route!!<<<<
>       }
>       [...bla, bla, bla...]
>       while (hasStuffToSend) {
>           producer.setBody(stuff[i]);
>       }
>   }
> }
>
>