How to programmatically find next downstream endpoint in a route.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to programmatically find next downstream endpoint in a route.

Chris Wolf
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]);
       }
   }
}


Reply | Threaded
Open this post in threaded view
|

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

James Carman
Does a splitter not work for you in this case?

On Fri, Oct 4, 2013 at 1:28 PM, Chris <[hidden email]> 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]);
>       }
>   }
> }
>
>
Reply | Threaded
Open this post in threaded view
|

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

Chris Wolf
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 <[hidden email]> 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]);
>>        }
>>    }
>> }
>>
>>
Reply | Threaded
Open this post in threaded view
|

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

James Carman
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 <[hidden email]> 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 <[hidden email]> 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]);
>>>        }
>>>    }
>>> }
>>>
>>>
>