You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by Quinn Stevenson <qu...@pronoia-solutions.com> on 2016/12/08 23:38:34 UTC

How to determine routeId for an endpoint at startup

I’m trying to get the Camel route Id of the route that my component is running inside when my component is started, but I can’t seem to figure out how to navigate the Camel APIs to get what I’m after.

I have basically a DefaultEndpoint, and from that endpoint, I need to get the routeId.

Any ideas?




Re: How to determine routeId for an endpoint at startup

Posted by Claus Ibsen <cl...@gmail.com>.
Take a look at camel-metrics. You can use a route factory where you
can then configure it once, and then it can add those route policy for
those routes where you use that given endpoint.

On Fri, Dec 9, 2016 at 3:19 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> Yes AFAIR that was not support today. That was what  the ticket was
> about. I managed to find it
> https://issues.apache.org/jira/browse/CAMEL-3183
>
> However that api change was likely to invasive. We can cope up with a
> better api, where a consumer could maybe implement some interface for
> having route id injected or something.
>
> Maybe we should log a new JIRA.
>
> What you can do is to have the component add a route policy which then
> does some logic in the onRouteInit method where you can then check if
> the route is consuming from that endpoint from your component and then
> do what you need to do before its started.
>
> And mind that all endpoints/consumers etc are not using in a route.
> You can also create it outside a route such as from @Consume on beans
> or manually from java code. But most use-cases are of course with
> routes.
>
> On Fri, Dec 9, 2016 at 3:09 PM, Quinn Stevenson
> <qu...@pronoia-solutions.com> wrote:
>> Thank You Claus - but I must not have stated my question very well ;-)
>>
>> I’m working on a custom Camel component - and Event Driver Consumer to be precise. When the component starts-up, I’d like to get the Camel route ID of the route that is using the component.
>>
>> I’m extending org.apache.camel.impl.DefaultConsumer for this consumer, so I’d like to get the route id when I implement the doStart() method.  Hopefully that makes sense.
>>
>>> On Dec 9, 2016, at 1:26 AM, Claus Ibsen <cl...@gmail.com> wrote:
>>>
>>> You can use a RoutePolicy which has callbacks when routes are
>>> initialized / started etc where you can get hold of the endpoint.
>>>
>>> There is a JIRA about allowing a consumer to be endpoint aware. But I
>>> think this required some API changes and was deferred for Camel 3.x.
>>>
>>>
>>>
>>> On Fri, Dec 9, 2016 at 12:38 AM, Quinn Stevenson
>>> <qu...@pronoia-solutions.com> wrote:
>>>> I’m trying to get the Camel route Id of the route that my component is running inside when my component is started, but I can’t seem to figure out how to navigate the Camel APIs to get what I’m after.
>>>>
>>>> I have basically a DefaultEndpoint, and from that endpoint, I need to get the routeId.
>>>>
>>>> Any ideas?
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> http://davsclaus.com @davsclaus
>>> Camel in Action 2: https://www.manning.com/ibsen2
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: How to determine routeId for an endpoint at startup

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yes AFAIR that was not support today. That was what  the ticket was
about. I managed to find it
https://issues.apache.org/jira/browse/CAMEL-3183

However that api change was likely to invasive. We can cope up with a
better api, where a consumer could maybe implement some interface for
having route id injected or something.

Maybe we should log a new JIRA.

What you can do is to have the component add a route policy which then
does some logic in the onRouteInit method where you can then check if
the route is consuming from that endpoint from your component and then
do what you need to do before its started.

And mind that all endpoints/consumers etc are not using in a route.
You can also create it outside a route such as from @Consume on beans
or manually from java code. But most use-cases are of course with
routes.

On Fri, Dec 9, 2016 at 3:09 PM, Quinn Stevenson
<qu...@pronoia-solutions.com> wrote:
> Thank You Claus - but I must not have stated my question very well ;-)
>
> I’m working on a custom Camel component - and Event Driver Consumer to be precise. When the component starts-up, I’d like to get the Camel route ID of the route that is using the component.
>
> I’m extending org.apache.camel.impl.DefaultConsumer for this consumer, so I’d like to get the route id when I implement the doStart() method.  Hopefully that makes sense.
>
>> On Dec 9, 2016, at 1:26 AM, Claus Ibsen <cl...@gmail.com> wrote:
>>
>> You can use a RoutePolicy which has callbacks when routes are
>> initialized / started etc where you can get hold of the endpoint.
>>
>> There is a JIRA about allowing a consumer to be endpoint aware. But I
>> think this required some API changes and was deferred for Camel 3.x.
>>
>>
>>
>> On Fri, Dec 9, 2016 at 12:38 AM, Quinn Stevenson
>> <qu...@pronoia-solutions.com> wrote:
>>> I’m trying to get the Camel route Id of the route that my component is running inside when my component is started, but I can’t seem to figure out how to navigate the Camel APIs to get what I’m after.
>>>
>>> I have basically a DefaultEndpoint, and from that endpoint, I need to get the routeId.
>>>
>>> Any ideas?
>>>
>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: How to determine routeId for an endpoint at startup

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
Thank You Claus - but I must not have stated my question very well ;-)

I’m working on a custom Camel component - and Event Driver Consumer to be precise. When the component starts-up, I’d like to get the Camel route ID of the route that is using the component.  

I’m extending org.apache.camel.impl.DefaultConsumer for this consumer, so I’d like to get the route id when I implement the doStart() method.  Hopefully that makes sense.

> On Dec 9, 2016, at 1:26 AM, Claus Ibsen <cl...@gmail.com> wrote:
> 
> You can use a RoutePolicy which has callbacks when routes are
> initialized / started etc where you can get hold of the endpoint.
> 
> There is a JIRA about allowing a consumer to be endpoint aware. But I
> think this required some API changes and was deferred for Camel 3.x.
> 
> 
> 
> On Fri, Dec 9, 2016 at 12:38 AM, Quinn Stevenson
> <qu...@pronoia-solutions.com> wrote:
>> I’m trying to get the Camel route Id of the route that my component is running inside when my component is started, but I can’t seem to figure out how to navigate the Camel APIs to get what I’m after.
>> 
>> I have basically a DefaultEndpoint, and from that endpoint, I need to get the routeId.
>> 
>> Any ideas?
>> 
>> 
>> 
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2


Re: How to determine routeId for an endpoint at startup

Posted by Claus Ibsen <cl...@gmail.com>.
You can use a RoutePolicy which has callbacks when routes are
initialized / started etc where you can get hold of the endpoint.

There is a JIRA about allowing a consumer to be endpoint aware. But I
think this required some API changes and was deferred for Camel 3.x.



On Fri, Dec 9, 2016 at 12:38 AM, Quinn Stevenson
<qu...@pronoia-solutions.com> wrote:
> I’m trying to get the Camel route Id of the route that my component is running inside when my component is started, but I can’t seem to figure out how to navigate the Camel APIs to get what I’m after.
>
> I have basically a DefaultEndpoint, and from that endpoint, I need to get the routeId.
>
> Any ideas?
>
>
>



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2