You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Ashwin Karpe <ak...@fusesource.com> on 2011/09/01 17:57:08 UTC

Re: Activemq dynamic endpoint configuration

Hi,

I believe you are going about this completely wrong.

What you need is to set up an EventManager object/entity that can keep an
eye on ActiveMQ using Advisory queues/topics or JMX to figure out the queues
and whether there are messages on these queues/topics. 

The this EventManager needs to be able to perform route lifecycle operations
(aka start, stop, suspend & resume routes) as and when queues and topics
contain messages or are drained.

Obviously, this solution becomes rather expensive and ineffective if the
drained queues fill up after very short waits since the Event Manager will
spend a most of its time starting and stopping routes for little value.

If you have a reference to the camel context, starting, stopping, suspending
and resuming routes is all simple and API driven.

Note that when you stop routes, you must take care to ensure that there are
no exchanges being processed by the route at the time. There is a graceful
shutdown on routes so please use this...

Hope this helps.

Cheers,

Ashwin...

-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
--
View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4758889.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Activemq dynamic endpoint configuration

Posted by Mick Knutson <mk...@baselogic.com>.
I looked at that link and did not see an example of how to use the event
driven consumer. Are there any code examples?

---
Thank You…

Mick Knutson, President

BASE Logic, Inc.
Enterprise Architecture, Design, Mentoring & Agile Consulting
p. (855) BASE-LOGIC: (227-3564-42)
p. (478) BASE-LOGIC (227-3564-42)
f. (855) BASE-LOGIC: (227-3564-42)

Website: http://www.baselogic.com
Blog: http://www.baselogic.com/blog/
Linked IN: http://linkedin.com/in/mickknutson
Twitter: http://twitter.com/mickknutson
---



On Fri, Sep 2, 2011 at 2:07 AM, Claus Ibsen <cl...@gmail.com> wrote:

> The configure method is called *once* when Camel bootup and create the
> runtime routes from the model (eg RouteBuilder's).
>
> The JMS consumer is an event driven consumer
> http://camel.apache.org/event-driven-consumer.html
>
>
>
>
> On Fri, Sep 2, 2011 at 1:57 AM, kal2420 <ka...@cisco.com> wrote:
> > Ashwin,
> >
> >   Thanks, I agree this is a bad approach.  I am a bit confused about how
> > often configure() method is invoked and when the message would be read
> from
> > the queue.  For Example:
> >
> >  public class TestRouteBuilder extends RouteBuilder {
> >
> >    public String current_State = "process";
> >
> >    @Override
> >    public void configure() throws Exception {
> >
> >          String selector = generateSelectorURI(current_state);
> >
> >        from("activemq:queue:test?selector="+selector)
> >                .to("log:test")
> >                .process(new Processor() {
> >
> >                                        @Override
> >                                        public void process(Exchange
> exchange) throws Exception {
> >
> >                                                current_State="waiting";
> >                                                sendSoapRequest("test");
> >                                        }
> >                                });
> >    }
> > }
> >
> > I only want to read and process messages if current_state is “process” (
> so
> > in "waiting" state change selector value so none of the messages would be
> > read).
> >
> > What type of endpoint would camel create based on
> > “from(“activemq:queue..”)” ?  ex: polled or scheduled endpoint.
> >
> > Would the selector uri get re-created on every read? does camel just
> change
> > endpoint configuration or re-create a new endpoint ?
> >
> > If you have a good example on how to do dynamic selector with
> > camel/activemq, I would love to see it.
> >
> > I really appreciate all your help.
> >
> > Thanks
> > Kal
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4760387.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>

Re: Activemq dynamic endpoint configuration

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Oct 4, 2011 at 1:29 AM, kal2420 <ka...@cisco.com> wrote:
> Claus,
>
>    What is the proper way to shutdown the route? I am doing the following from RouteBuilder:
>
>     getContext().stopRoute(routeID);
>
>  But when I do that, I all the routes being shutdown. is this correct ?  I see it invoking  "org.apache.camel.impl.DefaultShutdownStrategy$ShutdownTasK "  and "ShutdownStrategy".
>

That is the correct way. It "reuses" the shutdown logic, but is
limited to the given routeID.


> Thanks
> Kal
>
> On Sep 30, 2011, at 11:50 AM, Claus Ibsen-2 [via Camel] wrote:
>
>> On Fri, Sep 30, 2011 at 1:42 AM, kal2420 <[hidden email]> wrote:
>> > Thanks Clause,  I will give it a try this week end and see how it goes. Starting and stoping the route seems a bit expensive, can I use suspend and resume?
>> >
>>
>> You can try. But you may have to stop for the selector to be updated.
>> But give it a go first.
>>
>>
>> > Thanks
>> > Kal
>> >
>> > On Sep 28, 2011, at 2:01 AM, Claus Ibsen-2 [via Camel] wrote:
>> >
>> >> Hi
>> >>
>> >> Yes you would need to stop the route. Adjust the endpoint. And start
>> >> the route again to have the JMS selector dynamic updated.
>> >>
>> >> CamelContext has API to start/stop rotues by the route id.
>> >>
>> >>
>> >> On Wed, Sep 28, 2011 at 5:10 AM, kal2420 <[hidden email]> wrote:
>> >>
>> >> > Thanks Claus,
>> >> >
>> >> >    This example is very helpful, I am still running into a bit of an issues. Here is my createRouteBuilder() method ( combined JmsSelectorTest and JmsSelectorInTest ) :
>> >> >
>> >> >   @Override
>> >> >    protected RouteBuilder createRouteBuilder() throws Exception {
>> >> >        return new RouteBuilder() {
>> >> >            @Override
>> >> >            public void configure() throws Exception {
>> >> >                JmsEndpoint endpoint = context.getEndpoint("activemq:test.b", JmsEndpoint.class);
>> >> >                endpoint.setSelector("selector=cheese='y'");
>> >> >
>> >> >                from("activemq:test.a").to("activemq:test.b");
>> >> >
>> >> >                // from("activemq:test.b?selector=cheese='y'").to("mock:result");
>> >> >                from(endpoint).routeId("route-b").to("mock:result");
>> >> >
>> >> >                from("activemq:test.c").process(new Processor() {
>> >> >
>> >> >                    @Override
>> >> >                    public void process(Exchange arg0) throws Exception {
>> >> >
>> >> >                        //==================================================
>> >> >                        //
>> >> >                        //      I want to change selector on an endpoint at run time
>> >> >                        //       does it require an endpoint restart ?
>> >> >                        //==================================================
>> >> >
>> >> >                        CamelContext ctx = getContext();
>> >> >                        Route rt = ctx.getRoute("route-b");
>> >> >                        JmsEndpoint endpoint = (JmsEndpoint) rt.getEndpoint();
>> >> >                        endpoint.setSelector("cheese IN ('x', 'n')");
>> >> >
>> >> >                    }
>> >> >                }).to("activemq:test.b");
>> >> >            }
>> >> >        };
>> >> >    }
>> >> >
>> >> >
>> >> > I noticed that if I define the selector as part of the uri every thing works, but I want to dynamically change the selector at runtime.  Let me know if I am doing something wrong here.
>> >> >
>> >> > Thanks
>> >> > Kal
>> >> >
>> >> > On Sep 27, 2011, at 8:09 AM, Claus Ibsen-2 [via Camel] wrote:
>> >> >
>> >> >> Hi
>> >> >>
>> >> >> I created an unit test which you can take a look at. It uses the IN selector
>> >> >> http://svn.apache.org/viewvc?rev=1176348&view=rev
>> >> >>
>> >> >> On Tue, Sep 27, 2011 at 1:58 PM, Claus Ibsen <[hidden email]> wrote:
>> >> >>
>> >> >> > On Mon, Sep 26, 2011 at 6:05 PM, kal2420 <[hidden email]> wrote:
>> >> >> >> Thanks Claus,
>> >> >> >>
>> >> >> >>     I got busy with work, and I am just getting back to camel. I did try
>> >> >> >> looking into event-driven-consusmer, What i really want is to configure
>> >> >> >> dynamic selector on activemq queue. Here is how I am trying to configure
>> >> >> >> dynamic selector, please tell me if this is correct:
>> >> >> >>
>> >> >> >> // once all routes are up and running
>> >> >> >> // set selector on jms endpoint
>> >> >> >> CamelContext ctx = getContext();
>> >> >> >> JmsEndpoint endpoint =
>> >> >> >> ctx.getEndpoint("activemq://queue:test-1",JmsEndpoint.class);
>> >> >> >>  // String selector = "userid='test12'";  // also tried with %3D url format
>> >> >> >> String selector = "userid IN ('test12' , 'terst234');
>> >> >> >>  endpoint.setSelector(selector);
>> >> >> >>
>> >> >> >
>> >> >> > So you have a route with that particular endpoint
>> >> >> > from(endpoint).to("xxx")
>> >> >> >
>> >> >> >
>> >> >> > The selector should use a SQL like syntax. I actually do not know if
>> >> >> > ActiveMQ has an logging to WARN/ERROR level
>> >> >> > if the syntax is invalid.
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >> Issue:  I am seeing all messages being processed, while i only want to
>> >> >> >> process messages where i have userid header value set to 'test12' or
>> >> >> >> 'terst234'
>> >> >> >>
>> >> >> >> Thanks
>> >> >> >> Kal
>> >> >> >>
>> >> >> >> --
>> >> >> >> View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4841926.html
>> >> >> >> Sent from the Camel - Users mailing list archive at Nabble.com.
>> >> >> >>
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > --
>> >> >> > Claus Ibsen
>> >> >> > -----------------
>> >> >> > FuseSource
>> >> >> > Email: [hidden email]
>> >> >> > Web: http://fusesource.com
>> >> >> > Twitter: davsclaus, fusenews
>> >> >> > Blog: http://davsclaus.blogspot.com/
>> >> >> > Author of Camel in Action: http://www.manning.com/ibsen/
>> >> >> >
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Claus Ibsen
>> >> >> -----------------
>> >> >> FuseSource
>> >> >> Email: [hidden email]
>> >> >> Web: http://fusesource.com
>> >> >> Twitter: davsclaus, fusenews
>> >> >> Blog: http://davsclaus.blogspot.com/
>> >> >> Author of Camel in Action: http://www.manning.com/ibsen/
>> >> >>
>> >> >>
>> >> >> If you reply to this email, your message will be added to the discussion below:
>> >> >> http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4845119.html
>> >> >> To unsubscribe from Activemq dynamic endpoint configuration, click here.
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4847785.html
>> >> > Sent from the Camel - Users mailing list archive at Nabble.com.
>> >>
>> >>
>> >>
>> >> --
>> >> Claus Ibsen
>> >> -----------------
>> >> FuseSource
>> >> Email: [hidden email]
>> >> Web: http://fusesource.com
>> >> Twitter: davsclaus, fusenews
>> >> Blog: http://davsclaus.blogspot.com/
>> >> Author of Camel in Action: http://www.manning.com/ibsen/
>> >>
>> >>
>> >> If you reply to this email, your message will be added to the discussion below:
>> >> http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4848015.html
>> >> To unsubscribe from Activemq dynamic endpoint configuration, click here.
>> >
>> >
>> >
>> > --
>> > View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4855106.html
>> > Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> FuseSource
>> Email: [hidden email]
>> Web: http://fusesource.com
>> Twitter: davsclaus, fusenews
>> Blog: http://davsclaus.blogspot.com/
>> Author of Camel in Action: http://www.manning.com/ibsen/
>>
>>
>> If you reply to this email, your message will be added to the discussion below:
>> http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4857621.html
>> To unsubscribe from Activemq dynamic endpoint configuration, click here.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4866938.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Activemq dynamic endpoint configuration

Posted by kal2420 <ka...@cisco.com>.
Claus, 

    What is the proper way to shutdown the route? I am doing the following from RouteBuilder: 

     getContext().stopRoute(routeID);

 But when I do that, I all the routes being shutdown. is this correct ?  I see it invoking  "org.apache.camel.impl.DefaultShutdownStrategy$ShutdownTasK "  and "ShutdownStrategy". 

Thanks
Kal

On Sep 30, 2011, at 11:50 AM, Claus Ibsen-2 [via Camel] wrote:

> On Fri, Sep 30, 2011 at 1:42 AM, kal2420 <[hidden email]> wrote: 
> > Thanks Clause,  I will give it a try this week end and see how it goes. Starting and stoping the route seems a bit expensive, can I use suspend and resume? 
> > 
> 
> You can try. But you may have to stop for the selector to be updated. 
> But give it a go first. 
> 
> 
> > Thanks 
> > Kal 
> > 
> > On Sep 28, 2011, at 2:01 AM, Claus Ibsen-2 [via Camel] wrote: 
> > 
> >> Hi 
> >> 
> >> Yes you would need to stop the route. Adjust the endpoint. And start 
> >> the route again to have the JMS selector dynamic updated. 
> >> 
> >> CamelContext has API to start/stop rotues by the route id. 
> >> 
> >> 
> >> On Wed, Sep 28, 2011 at 5:10 AM, kal2420 <[hidden email]> wrote: 
> >> 
> >> > Thanks Claus, 
> >> > 
> >> >    This example is very helpful, I am still running into a bit of an issues. Here is my createRouteBuilder() method ( combined JmsSelectorTest and JmsSelectorInTest ) : 
> >> > 
> >> >   @Override 
> >> >    protected RouteBuilder createRouteBuilder() throws Exception { 
> >> >        return new RouteBuilder() { 
> >> >            @Override 
> >> >            public void configure() throws Exception { 
> >> >                JmsEndpoint endpoint = context.getEndpoint("activemq:test.b", JmsEndpoint.class); 
> >> >                endpoint.setSelector("selector=cheese='y'"); 
> >> > 
> >> >                from("activemq:test.a").to("activemq:test.b"); 
> >> > 
> >> >                // from("activemq:test.b?selector=cheese='y'").to("mock:result"); 
> >> >                from(endpoint).routeId("route-b").to("mock:result"); 
> >> > 
> >> >                from("activemq:test.c").process(new Processor() { 
> >> > 
> >> >                    @Override 
> >> >                    public void process(Exchange arg0) throws Exception { 
> >> > 
> >> >                        //================================================== 
> >> >                        // 
> >> >                        //      I want to change selector on an endpoint at run time 
> >> >                        //       does it require an endpoint restart ? 
> >> >                        //================================================== 
> >> > 
> >> >                        CamelContext ctx = getContext(); 
> >> >                        Route rt = ctx.getRoute("route-b"); 
> >> >                        JmsEndpoint endpoint = (JmsEndpoint) rt.getEndpoint(); 
> >> >                        endpoint.setSelector("cheese IN ('x', 'n')"); 
> >> > 
> >> >                    } 
> >> >                }).to("activemq:test.b"); 
> >> >            } 
> >> >        }; 
> >> >    } 
> >> > 
> >> > 
> >> > I noticed that if I define the selector as part of the uri every thing works, but I want to dynamically change the selector at runtime.  Let me know if I am doing something wrong here. 
> >> > 
> >> > Thanks 
> >> > Kal 
> >> > 
> >> > On Sep 27, 2011, at 8:09 AM, Claus Ibsen-2 [via Camel] wrote: 
> >> > 
> >> >> Hi 
> >> >> 
> >> >> I created an unit test which you can take a look at. It uses the IN selector 
> >> >> http://svn.apache.org/viewvc?rev=1176348&view=rev
> >> >> 
> >> >> On Tue, Sep 27, 2011 at 1:58 PM, Claus Ibsen <[hidden email]> wrote: 
> >> >> 
> >> >> > On Mon, Sep 26, 2011 at 6:05 PM, kal2420 <[hidden email]> wrote: 
> >> >> >> Thanks Claus, 
> >> >> >> 
> >> >> >>     I got busy with work, and I am just getting back to camel. I did try 
> >> >> >> looking into event-driven-consusmer, What i really want is to configure 
> >> >> >> dynamic selector on activemq queue. Here is how I am trying to configure 
> >> >> >> dynamic selector, please tell me if this is correct: 
> >> >> >> 
> >> >> >> // once all routes are up and running 
> >> >> >> // set selector on jms endpoint 
> >> >> >> CamelContext ctx = getContext(); 
> >> >> >> JmsEndpoint endpoint = 
> >> >> >> ctx.getEndpoint("activemq://queue:test-1",JmsEndpoint.class); 
> >> >> >>  // String selector = "userid='test12'";  // also tried with %3D url format 
> >> >> >> String selector = "userid IN ('test12' , 'terst234'); 
> >> >> >>  endpoint.setSelector(selector); 
> >> >> >> 
> >> >> > 
> >> >> > So you have a route with that particular endpoint 
> >> >> > from(endpoint).to("xxx") 
> >> >> > 
> >> >> > 
> >> >> > The selector should use a SQL like syntax. I actually do not know if 
> >> >> > ActiveMQ has an logging to WARN/ERROR level 
> >> >> > if the syntax is invalid. 
> >> >> > 
> >> >> > 
> >> >> > 
> >> >> >> Issue:  I am seeing all messages being processed, while i only want to 
> >> >> >> process messages where i have userid header value set to 'test12' or 
> >> >> >> 'terst234' 
> >> >> >> 
> >> >> >> Thanks 
> >> >> >> Kal 
> >> >> >> 
> >> >> >> -- 
> >> >> >> View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4841926.html
> >> >> >> Sent from the Camel - Users mailing list archive at Nabble.com. 
> >> >> >> 
> >> >> > 
> >> >> > 
> >> >> > 
> >> >> > -- 
> >> >> > Claus Ibsen 
> >> >> > ----------------- 
> >> >> > FuseSource 
> >> >> > Email: [hidden email] 
> >> >> > Web: http://fusesource.com
> >> >> > Twitter: davsclaus, fusenews 
> >> >> > Blog: http://davsclaus.blogspot.com/
> >> >> > Author of Camel in Action: http://www.manning.com/ibsen/
> >> >> > 
> >> >> 
> >> >> 
> >> >> 
> >> >> -- 
> >> >> Claus Ibsen 
> >> >> ----------------- 
> >> >> FuseSource 
> >> >> Email: [hidden email] 
> >> >> Web: http://fusesource.com
> >> >> Twitter: davsclaus, fusenews 
> >> >> Blog: http://davsclaus.blogspot.com/
> >> >> Author of Camel in Action: http://www.manning.com/ibsen/
> >> >> 
> >> >> 
> >> >> If you reply to this email, your message will be added to the discussion below: 
> >> >> http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4845119.html
> >> >> To unsubscribe from Activemq dynamic endpoint configuration, click here. 
> >> > 
> >> > 
> >> > 
> >> > -- 
> >> > View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4847785.html
> >> > Sent from the Camel - Users mailing list archive at Nabble.com. 
> >> 
> >> 
> >> 
> >> -- 
> >> Claus Ibsen 
> >> ----------------- 
> >> FuseSource 
> >> Email: [hidden email] 
> >> Web: http://fusesource.com
> >> Twitter: davsclaus, fusenews 
> >> Blog: http://davsclaus.blogspot.com/
> >> Author of Camel in Action: http://www.manning.com/ibsen/
> >> 
> >> 
> >> If you reply to this email, your message will be added to the discussion below: 
> >> http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4848015.html
> >> To unsubscribe from Activemq dynamic endpoint configuration, click here. 
> > 
> > 
> > 
> > -- 
> > View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4855106.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> Claus Ibsen 
> ----------------- 
> FuseSource 
> Email: [hidden email] 
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews 
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
> 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4857621.html
> To unsubscribe from Activemq dynamic endpoint configuration, click here.



--
View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4866938.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Activemq dynamic endpoint configuration

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Sep 30, 2011 at 1:42 AM, kal2420 <ka...@cisco.com> wrote:
> Thanks Clause,  I will give it a try this week end and see how it goes. Starting and stoping the route seems a bit expensive, can I use suspend and resume?
>

You can try. But you may have to stop for the selector to be updated.
But give it a go first.


> Thanks
> Kal
>
> On Sep 28, 2011, at 2:01 AM, Claus Ibsen-2 [via Camel] wrote:
>
>> Hi
>>
>> Yes you would need to stop the route. Adjust the endpoint. And start
>> the route again to have the JMS selector dynamic updated.
>>
>> CamelContext has API to start/stop rotues by the route id.
>>
>>
>> On Wed, Sep 28, 2011 at 5:10 AM, kal2420 <[hidden email]> wrote:
>>
>> > Thanks Claus,
>> >
>> >    This example is very helpful, I am still running into a bit of an issues. Here is my createRouteBuilder() method ( combined JmsSelectorTest and JmsSelectorInTest ) :
>> >
>> >   @Override
>> >    protected RouteBuilder createRouteBuilder() throws Exception {
>> >        return new RouteBuilder() {
>> >            @Override
>> >            public void configure() throws Exception {
>> >                JmsEndpoint endpoint = context.getEndpoint("activemq:test.b", JmsEndpoint.class);
>> >                endpoint.setSelector("selector=cheese='y'");
>> >
>> >                from("activemq:test.a").to("activemq:test.b");
>> >
>> >                // from("activemq:test.b?selector=cheese='y'").to("mock:result");
>> >                from(endpoint).routeId("route-b").to("mock:result");
>> >
>> >                from("activemq:test.c").process(new Processor() {
>> >
>> >                    @Override
>> >                    public void process(Exchange arg0) throws Exception {
>> >
>> >                        //==================================================
>> >                        //
>> >                        //      I want to change selector on an endpoint at run time
>> >                        //       does it require an endpoint restart ?
>> >                        //==================================================
>> >
>> >                        CamelContext ctx = getContext();
>> >                        Route rt = ctx.getRoute("route-b");
>> >                        JmsEndpoint endpoint = (JmsEndpoint) rt.getEndpoint();
>> >                        endpoint.setSelector("cheese IN ('x', 'n')");
>> >
>> >                    }
>> >                }).to("activemq:test.b");
>> >            }
>> >        };
>> >    }
>> >
>> >
>> > I noticed that if I define the selector as part of the uri every thing works, but I want to dynamically change the selector at runtime.  Let me know if I am doing something wrong here.
>> >
>> > Thanks
>> > Kal
>> >
>> > On Sep 27, 2011, at 8:09 AM, Claus Ibsen-2 [via Camel] wrote:
>> >
>> >> Hi
>> >>
>> >> I created an unit test which you can take a look at. It uses the IN selector
>> >> http://svn.apache.org/viewvc?rev=1176348&view=rev
>> >>
>> >> On Tue, Sep 27, 2011 at 1:58 PM, Claus Ibsen <[hidden email]> wrote:
>> >>
>> >> > On Mon, Sep 26, 2011 at 6:05 PM, kal2420 <[hidden email]> wrote:
>> >> >> Thanks Claus,
>> >> >>
>> >> >>     I got busy with work, and I am just getting back to camel. I did try
>> >> >> looking into event-driven-consusmer, What i really want is to configure
>> >> >> dynamic selector on activemq queue. Here is how I am trying to configure
>> >> >> dynamic selector, please tell me if this is correct:
>> >> >>
>> >> >> // once all routes are up and running
>> >> >> // set selector on jms endpoint
>> >> >> CamelContext ctx = getContext();
>> >> >> JmsEndpoint endpoint =
>> >> >> ctx.getEndpoint("activemq://queue:test-1",JmsEndpoint.class);
>> >> >>  // String selector = "userid='test12'";  // also tried with %3D url format
>> >> >> String selector = "userid IN ('test12' , 'terst234');
>> >> >>  endpoint.setSelector(selector);
>> >> >>
>> >> >
>> >> > So you have a route with that particular endpoint
>> >> > from(endpoint).to("xxx")
>> >> >
>> >> >
>> >> > The selector should use a SQL like syntax. I actually do not know if
>> >> > ActiveMQ has an logging to WARN/ERROR level
>> >> > if the syntax is invalid.
>> >> >
>> >> >
>> >> >
>> >> >> Issue:  I am seeing all messages being processed, while i only want to
>> >> >> process messages where i have userid header value set to 'test12' or
>> >> >> 'terst234'
>> >> >>
>> >> >> Thanks
>> >> >> Kal
>> >> >>
>> >> >> --
>> >> >> View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4841926.html
>> >> >> Sent from the Camel - Users mailing list archive at Nabble.com.
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Claus Ibsen
>> >> > -----------------
>> >> > FuseSource
>> >> > Email: [hidden email]
>> >> > Web: http://fusesource.com
>> >> > Twitter: davsclaus, fusenews
>> >> > Blog: http://davsclaus.blogspot.com/
>> >> > Author of Camel in Action: http://www.manning.com/ibsen/
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Claus Ibsen
>> >> -----------------
>> >> FuseSource
>> >> Email: [hidden email]
>> >> Web: http://fusesource.com
>> >> Twitter: davsclaus, fusenews
>> >> Blog: http://davsclaus.blogspot.com/
>> >> Author of Camel in Action: http://www.manning.com/ibsen/
>> >>
>> >>
>> >> If you reply to this email, your message will be added to the discussion below:
>> >> http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4845119.html
>> >> To unsubscribe from Activemq dynamic endpoint configuration, click here.
>> >
>> >
>> >
>> > --
>> > View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4847785.html
>> > Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> FuseSource
>> Email: [hidden email]
>> Web: http://fusesource.com
>> Twitter: davsclaus, fusenews
>> Blog: http://davsclaus.blogspot.com/
>> Author of Camel in Action: http://www.manning.com/ibsen/
>>
>>
>> If you reply to this email, your message will be added to the discussion below:
>> http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4848015.html
>> To unsubscribe from Activemq dynamic endpoint configuration, click here.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4855106.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Activemq dynamic endpoint configuration

Posted by kal2420 <ka...@cisco.com>.
Thanks Clause,  I will give it a try this week end and see how it goes. Starting and stoping the route seems a bit expensive, can I use suspend and resume? 

Thanks
Kal

On Sep 28, 2011, at 2:01 AM, Claus Ibsen-2 [via Camel] wrote:

> Hi 
> 
> Yes you would need to stop the route. Adjust the endpoint. And start 
> the route again to have the JMS selector dynamic updated. 
> 
> CamelContext has API to start/stop rotues by the route id. 
> 
> 
> On Wed, Sep 28, 2011 at 5:10 AM, kal2420 <[hidden email]> wrote:
> 
> > Thanks Claus, 
> > 
> >    This example is very helpful, I am still running into a bit of an issues. Here is my createRouteBuilder() method ( combined JmsSelectorTest and JmsSelectorInTest ) : 
> > 
> >   @Override 
> >    protected RouteBuilder createRouteBuilder() throws Exception { 
> >        return new RouteBuilder() { 
> >            @Override 
> >            public void configure() throws Exception { 
> >                JmsEndpoint endpoint = context.getEndpoint("activemq:test.b", JmsEndpoint.class); 
> >                endpoint.setSelector("selector=cheese='y'"); 
> > 
> >                from("activemq:test.a").to("activemq:test.b"); 
> > 
> >                // from("activemq:test.b?selector=cheese='y'").to("mock:result"); 
> >                from(endpoint).routeId("route-b").to("mock:result"); 
> > 
> >                from("activemq:test.c").process(new Processor() { 
> > 
> >                    @Override 
> >                    public void process(Exchange arg0) throws Exception { 
> > 
> >                        //================================================== 
> >                        // 
> >                        //      I want to change selector on an endpoint at run time 
> >                        //       does it require an endpoint restart ? 
> >                        //================================================== 
> > 
> >                        CamelContext ctx = getContext(); 
> >                        Route rt = ctx.getRoute("route-b"); 
> >                        JmsEndpoint endpoint = (JmsEndpoint) rt.getEndpoint(); 
> >                        endpoint.setSelector("cheese IN ('x', 'n')"); 
> > 
> >                    } 
> >                }).to("activemq:test.b"); 
> >            } 
> >        }; 
> >    } 
> > 
> > 
> > I noticed that if I define the selector as part of the uri every thing works, but I want to dynamically change the selector at runtime.  Let me know if I am doing something wrong here. 
> > 
> > Thanks 
> > Kal 
> > 
> > On Sep 27, 2011, at 8:09 AM, Claus Ibsen-2 [via Camel] wrote: 
> > 
> >> Hi 
> >> 
> >> I created an unit test which you can take a look at. It uses the IN selector 
> >> http://svn.apache.org/viewvc?rev=1176348&view=rev
> >> 
> >> On Tue, Sep 27, 2011 at 1:58 PM, Claus Ibsen <[hidden email]> wrote: 
> >> 
> >> > On Mon, Sep 26, 2011 at 6:05 PM, kal2420 <[hidden email]> wrote: 
> >> >> Thanks Claus, 
> >> >> 
> >> >>     I got busy with work, and I am just getting back to camel. I did try 
> >> >> looking into event-driven-consusmer, What i really want is to configure 
> >> >> dynamic selector on activemq queue. Here is how I am trying to configure 
> >> >> dynamic selector, please tell me if this is correct: 
> >> >> 
> >> >> // once all routes are up and running 
> >> >> // set selector on jms endpoint 
> >> >> CamelContext ctx = getContext(); 
> >> >> JmsEndpoint endpoint = 
> >> >> ctx.getEndpoint("activemq://queue:test-1",JmsEndpoint.class); 
> >> >>  // String selector = "userid='test12'";  // also tried with %3D url format 
> >> >> String selector = "userid IN ('test12' , 'terst234'); 
> >> >>  endpoint.setSelector(selector); 
> >> >> 
> >> > 
> >> > So you have a route with that particular endpoint 
> >> > from(endpoint).to("xxx") 
> >> > 
> >> > 
> >> > The selector should use a SQL like syntax. I actually do not know if 
> >> > ActiveMQ has an logging to WARN/ERROR level 
> >> > if the syntax is invalid. 
> >> > 
> >> > 
> >> > 
> >> >> Issue:  I am seeing all messages being processed, while i only want to 
> >> >> process messages where i have userid header value set to 'test12' or 
> >> >> 'terst234' 
> >> >> 
> >> >> Thanks 
> >> >> Kal 
> >> >> 
> >> >> -- 
> >> >> View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4841926.html
> >> >> Sent from the Camel - Users mailing list archive at Nabble.com. 
> >> >> 
> >> > 
> >> > 
> >> > 
> >> > -- 
> >> > Claus Ibsen 
> >> > ----------------- 
> >> > FuseSource 
> >> > Email: [hidden email] 
> >> > Web: http://fusesource.com
> >> > Twitter: davsclaus, fusenews 
> >> > Blog: http://davsclaus.blogspot.com/
> >> > Author of Camel in Action: http://www.manning.com/ibsen/
> >> > 
> >> 
> >> 
> >> 
> >> -- 
> >> Claus Ibsen 
> >> ----------------- 
> >> FuseSource 
> >> Email: [hidden email] 
> >> Web: http://fusesource.com
> >> Twitter: davsclaus, fusenews 
> >> Blog: http://davsclaus.blogspot.com/
> >> Author of Camel in Action: http://www.manning.com/ibsen/
> >> 
> >> 
> >> If you reply to this email, your message will be added to the discussion below: 
> >> http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4845119.html
> >> To unsubscribe from Activemq dynamic endpoint configuration, click here. 
> > 
> > 
> > 
> > -- 
> > View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4847785.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> Claus Ibsen 
> ----------------- 
> FuseSource 
> Email: [hidden email] 
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews 
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
> 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4848015.html
> To unsubscribe from Activemq dynamic endpoint configuration, click here.



--
View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4855106.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Activemq dynamic endpoint configuration

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

Yes you would need to stop the route. Adjust the endpoint. And start
the route again to have the JMS selector dynamic updated.

CamelContext has API to start/stop rotues by the route id.


On Wed, Sep 28, 2011 at 5:10 AM, kal2420 <ka...@cisco.com> wrote:
> Thanks Claus,
>
>    This example is very helpful, I am still running into a bit of an issues. Here is my createRouteBuilder() method ( combined JmsSelectorTest and JmsSelectorInTest ) :
>
>   @Override
>    protected RouteBuilder createRouteBuilder() throws Exception {
>        return new RouteBuilder() {
>            @Override
>            public void configure() throws Exception {
>                JmsEndpoint endpoint = context.getEndpoint("activemq:test.b", JmsEndpoint.class);
>                endpoint.setSelector("selector=cheese='y'");
>
>                from("activemq:test.a").to("activemq:test.b");
>
>                // from("activemq:test.b?selector=cheese='y'").to("mock:result");
>                from(endpoint).routeId("route-b").to("mock:result");
>
>                from("activemq:test.c").process(new Processor() {
>
>                    @Override
>                    public void process(Exchange arg0) throws Exception {
>
>                        //==================================================
>                        //
>                        //      I want to change selector on an endpoint at run time
>                        //       does it require an endpoint restart ?
>                        //==================================================
>
>                        CamelContext ctx = getContext();
>                        Route rt = ctx.getRoute("route-b");
>                        JmsEndpoint endpoint = (JmsEndpoint) rt.getEndpoint();
>                        endpoint.setSelector("cheese IN ('x', 'n')");
>
>                    }
>                }).to("activemq:test.b");
>            }
>        };
>    }
>
>
> I noticed that if I define the selector as part of the uri every thing works, but I want to dynamically change the selector at runtime.  Let me know if I am doing something wrong here.
>
> Thanks
> Kal
>
> On Sep 27, 2011, at 8:09 AM, Claus Ibsen-2 [via Camel] wrote:
>
>> Hi
>>
>> I created an unit test which you can take a look at. It uses the IN selector
>> http://svn.apache.org/viewvc?rev=1176348&view=rev
>>
>> On Tue, Sep 27, 2011 at 1:58 PM, Claus Ibsen <[hidden email]> wrote:
>>
>> > On Mon, Sep 26, 2011 at 6:05 PM, kal2420 <[hidden email]> wrote:
>> >> Thanks Claus,
>> >>
>> >>     I got busy with work, and I am just getting back to camel. I did try
>> >> looking into event-driven-consusmer, What i really want is to configure
>> >> dynamic selector on activemq queue. Here is how I am trying to configure
>> >> dynamic selector, please tell me if this is correct:
>> >>
>> >> // once all routes are up and running
>> >> // set selector on jms endpoint
>> >> CamelContext ctx = getContext();
>> >> JmsEndpoint endpoint =
>> >> ctx.getEndpoint("activemq://queue:test-1",JmsEndpoint.class);
>> >>  // String selector = "userid='test12'";  // also tried with %3D url format
>> >> String selector = "userid IN ('test12' , 'terst234');
>> >>  endpoint.setSelector(selector);
>> >>
>> >
>> > So you have a route with that particular endpoint
>> > from(endpoint).to("xxx")
>> >
>> >
>> > The selector should use a SQL like syntax. I actually do not know if
>> > ActiveMQ has an logging to WARN/ERROR level
>> > if the syntax is invalid.
>> >
>> >
>> >
>> >> Issue:  I am seeing all messages being processed, while i only want to
>> >> process messages where i have userid header value set to 'test12' or
>> >> 'terst234'
>> >>
>> >> Thanks
>> >> Kal
>> >>
>> >> --
>> >> View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4841926.html
>> >> Sent from the Camel - Users mailing list archive at Nabble.com.
>> >>
>> >
>> >
>> >
>> > --
>> > Claus Ibsen
>> > -----------------
>> > FuseSource
>> > Email: [hidden email]
>> > Web: http://fusesource.com
>> > Twitter: davsclaus, fusenews
>> > Blog: http://davsclaus.blogspot.com/
>> > Author of Camel in Action: http://www.manning.com/ibsen/
>> >
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> FuseSource
>> Email: [hidden email]
>> Web: http://fusesource.com
>> Twitter: davsclaus, fusenews
>> Blog: http://davsclaus.blogspot.com/
>> Author of Camel in Action: http://www.manning.com/ibsen/
>>
>>
>> If you reply to this email, your message will be added to the discussion below:
>> http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4845119.html
>> To unsubscribe from Activemq dynamic endpoint configuration, click here.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4847785.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Activemq dynamic endpoint configuration

Posted by kal2420 <ka...@cisco.com>.
Thanks Claus,  

    This example is very helpful, I am still running into a bit of an issues. Here is my createRouteBuilder() method ( combined JmsSelectorTest and JmsSelectorInTest ) :

   @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                JmsEndpoint endpoint = context.getEndpoint("activemq:test.b", JmsEndpoint.class);
                endpoint.setSelector("selector=cheese='y'");

                from("activemq:test.a").to("activemq:test.b");

                // from("activemq:test.b?selector=cheese='y'").to("mock:result");
                from(endpoint).routeId("route-b").to("mock:result");

                from("activemq:test.c").process(new Processor() {

                    @Override
                    public void process(Exchange arg0) throws Exception {
                        
			//==================================================
			//      
		  	//      I want to change selector on an endpoint at run time
			//       does it require an endpoint restart ? 
			//==================================================

                        CamelContext ctx = getContext();
                        Route rt = ctx.getRoute("route-b");
                        JmsEndpoint endpoint = (JmsEndpoint) rt.getEndpoint();
                        endpoint.setSelector("cheese IN ('x', 'n')");

                    }
                }).to("activemq:test.b");
            }
        };
    }


I noticed that if I define the selector as part of the uri every thing works, but I want to dynamically change the selector at runtime.  Let me know if I am doing something wrong here. 

Thanks
Kal

On Sep 27, 2011, at 8:09 AM, Claus Ibsen-2 [via Camel] wrote:

> Hi 
> 
> I created an unit test which you can take a look at. It uses the IN selector 
> http://svn.apache.org/viewvc?rev=1176348&view=rev
> 
> On Tue, Sep 27, 2011 at 1:58 PM, Claus Ibsen <[hidden email]> wrote:
> 
> > On Mon, Sep 26, 2011 at 6:05 PM, kal2420 <[hidden email]> wrote: 
> >> Thanks Claus, 
> >> 
> >>     I got busy with work, and I am just getting back to camel. I did try 
> >> looking into event-driven-consusmer, What i really want is to configure 
> >> dynamic selector on activemq queue. Here is how I am trying to configure 
> >> dynamic selector, please tell me if this is correct: 
> >> 
> >> // once all routes are up and running 
> >> // set selector on jms endpoint 
> >> CamelContext ctx = getContext(); 
> >> JmsEndpoint endpoint = 
> >> ctx.getEndpoint("activemq://queue:test-1",JmsEndpoint.class); 
> >>  // String selector = "userid='test12'";  // also tried with %3D url format 
> >> String selector = "userid IN ('test12' , 'terst234'); 
> >>  endpoint.setSelector(selector); 
> >> 
> > 
> > So you have a route with that particular endpoint 
> > from(endpoint).to("xxx") 
> > 
> > 
> > The selector should use a SQL like syntax. I actually do not know if 
> > ActiveMQ has an logging to WARN/ERROR level 
> > if the syntax is invalid. 
> > 
> > 
> > 
> >> Issue:  I am seeing all messages being processed, while i only want to 
> >> process messages where i have userid header value set to 'test12' or 
> >> 'terst234' 
> >> 
> >> Thanks 
> >> Kal 
> >> 
> >> -- 
> >> View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4841926.html
> >> Sent from the Camel - Users mailing list archive at Nabble.com. 
> >> 
> > 
> > 
> > 
> > -- 
> > Claus Ibsen 
> > ----------------- 
> > FuseSource 
> > Email: [hidden email] 
> > Web: http://fusesource.com
> > Twitter: davsclaus, fusenews 
> > Blog: http://davsclaus.blogspot.com/
> > Author of Camel in Action: http://www.manning.com/ibsen/
> >
> 
> 
> 
> -- 
> Claus Ibsen 
> ----------------- 
> FuseSource 
> Email: [hidden email] 
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews 
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
> 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4845119.html
> To unsubscribe from Activemq dynamic endpoint configuration, click here.



--
View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4847785.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Activemq dynamic endpoint configuration

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

I created an unit test which you can take a look at. It uses the IN selector
http://svn.apache.org/viewvc?rev=1176348&view=rev

On Tue, Sep 27, 2011 at 1:58 PM, Claus Ibsen <cl...@gmail.com> wrote:
> On Mon, Sep 26, 2011 at 6:05 PM, kal2420 <ka...@cisco.com> wrote:
>> Thanks Claus,
>>
>>     I got busy with work, and I am just getting back to camel. I did try
>> looking into event-driven-consusmer, What i really want is to configure
>> dynamic selector on activemq queue. Here is how I am trying to configure
>> dynamic selector, please tell me if this is correct:
>>
>> // once all routes are up and running
>> // set selector on jms endpoint
>> CamelContext ctx = getContext();
>> JmsEndpoint endpoint =
>> ctx.getEndpoint("activemq://queue:test-1",JmsEndpoint.class);
>>  // String selector = "userid='test12'";  // also tried with %3D url format
>> String selector = "userid IN ('test12' , 'terst234');
>>  endpoint.setSelector(selector);
>>
>
> So you have a route with that particular endpoint
> from(endpoint).to("xxx")
>
>
> The selector should use a SQL like syntax. I actually do not know if
> ActiveMQ has an logging to WARN/ERROR level
> if the syntax is invalid.
>
>
>
>> Issue:  I am seeing all messages being processed, while i only want to
>> process messages where i have userid header value set to 'test12' or
>> 'terst234'
>>
>> Thanks
>> Kal
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4841926.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Activemq dynamic endpoint configuration

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Sep 26, 2011 at 6:05 PM, kal2420 <ka...@cisco.com> wrote:
> Thanks Claus,
>
>     I got busy with work, and I am just getting back to camel. I did try
> looking into event-driven-consusmer, What i really want is to configure
> dynamic selector on activemq queue. Here is how I am trying to configure
> dynamic selector, please tell me if this is correct:
>
> // once all routes are up and running
> // set selector on jms endpoint
> CamelContext ctx = getContext();
> JmsEndpoint endpoint =
> ctx.getEndpoint("activemq://queue:test-1",JmsEndpoint.class);
>  // String selector = "userid='test12'";  // also tried with %3D url format
> String selector = "userid IN ('test12' , 'terst234');
>  endpoint.setSelector(selector);
>

So you have a route with that particular endpoint
from(endpoint).to("xxx")


The selector should use a SQL like syntax. I actually do not know if
ActiveMQ has an logging to WARN/ERROR level
if the syntax is invalid.



> Issue:  I am seeing all messages being processed, while i only want to
> process messages where i have userid header value set to 'test12' or
> 'terst234'
>
> Thanks
> Kal
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4841926.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Activemq dynamic endpoint configuration

Posted by kal2420 <ka...@cisco.com>.
Thanks Claus,

     I got busy with work, and I am just getting back to camel. I did try
looking into event-driven-consusmer, What i really want is to configure
dynamic selector on activemq queue. Here is how I am trying to configure
dynamic selector, please tell me if this is correct: 

// once all routes are up and running
// set selector on jms endpoint
CamelContext ctx = getContext();
JmsEndpoint endpoint =
ctx.getEndpoint("activemq://queue:test-1",JmsEndpoint.class);
 // String selector = "userid='test12'";  // also tried with %3D url format
String selector = "userid IN ('test12' , 'terst234');
 endpoint.setSelector(selector);

Issue:  I am seeing all messages being processed, while i only want to
process messages where i have userid header value set to 'test12' or
'terst234'

Thanks
Kal

--
View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4841926.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Activemq dynamic endpoint configuration

Posted by Claus Ibsen <cl...@gmail.com>.
The configure method is called *once* when Camel bootup and create the
runtime routes from the model (eg RouteBuilder's).

The JMS consumer is an event driven consumer
http://camel.apache.org/event-driven-consumer.html




On Fri, Sep 2, 2011 at 1:57 AM, kal2420 <ka...@cisco.com> wrote:
> Ashwin,
>
>   Thanks, I agree this is a bad approach.  I am a bit confused about how
> often configure() method is invoked and when the message would be read from
> the queue.  For Example:
>
>  public class TestRouteBuilder extends RouteBuilder {
>
>    public String current_State = "process";
>
>    @Override
>    public void configure() throws Exception {
>
>          String selector = generateSelectorURI(current_state);
>
>        from("activemq:queue:test?selector="+selector)
>                .to("log:test")
>                .process(new Processor() {
>
>                                        @Override
>                                        public void process(Exchange exchange) throws Exception {
>
>                                                current_State="waiting";
>                                                sendSoapRequest("test");
>                                        }
>                                });
>    }
> }
>
> I only want to read and process messages if current_state is “process” ( so
> in "waiting" state change selector value so none of the messages would be
> read).
>
> What type of endpoint would camel create based on
> “from(“activemq:queue..”)” ?  ex: polled or scheduled endpoint.
>
> Would the selector uri get re-created on every read? does camel just change
> endpoint configuration or re-create a new endpoint ?
>
> If you have a good example on how to do dynamic selector with
> camel/activemq, I would love to see it.
>
> I really appreciate all your help.
>
> Thanks
> Kal
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4760387.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

RE: Activemq dynamic endpoint configuration

Posted by kal2420 <ka...@cisco.com>.
mrlalonde wrote:
> 
> 
> I think you are on the right track with thoughts on polled endpoints.
> I you are looking to consume messages when a state changes, you could
> generate application events when that happens and use a pollEnrich(...)
> eip.
> 
> Something like:
> 
> from("spring-event://default").pollEnrich("activemq:queue:foo").process(...)...
> 
> You could use a timer endpoint instead of an application event if you want
> to poll based on a schedule.
> 
> 

 Thanks Mathieu, I have been on the road for past few days. I will try out
this approach and see how it goes.

Kal 

--
View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4776516.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: Activemq dynamic endpoint configuration

Posted by Mathieu Lalonde <mr...@live.ca>.
Kal,


from("activemq:queue:myQueue") would typically create a message driven consumer.

I think you are on the right track with thoughts on polled endpoints.
I you are looking to consume messages when a state changes, you could generate application events when that happens and use a pollEnrich(...) eip.

Something like:

from("spring-event://default").pollEnrich("activemq:queue:foo").process(...)...

You could use a timer endpoint instead of an application event if you want to poll based on a schedule.
Check out:
http://camel.apache.org/polling-consumer.html
http://camel.apache.org/content-enricher.html (pollEnrich section)

Of course there are other ways to activate the polling:
Camel Proxy Bean (to send to direct endpoints from pojos)
Camel Consumer Template

Hope this helps.  Good luck.

Mathieu






----------------------------------------
> Date: Thu, 1 Sep 2011 16:57:08 -0700
> From: kalpipat@cisco.com
> To: users@camel.apache.org
> Subject: Re: Activemq dynamic endpoint configuration
>
> Ashwin,
>
> Thanks, I agree this is a bad approach. I am a bit confused about how
> often configure() method is invoked and when the message would be read from
> the queue. For Example:
>
> public class TestRouteBuilder extends RouteBuilder {
>
> public String current_State = "process";
>
> @Override
> public void configure() throws Exception {
>
> String selector = generateSelectorURI(current_state);
>
> from("activemq:queue:test?selector="+selector)
> .to("log:test")
> .process(new Processor() {
>
> @Override
> public void process(Exchange exchange) throws Exception {
>
> current_State="waiting";
> sendSoapRequest("test");
> }
> });
> }
> }
>
> I only want to read and process messages if current_state is “process” ( so
> in "waiting" state change selector value so none of the messages would be
> read).
>
> What type of endpoint would camel create based on
> “from(“activemq:queue..”)” ? ex: polled or scheduled endpoint.
>
> Would the selector uri get re-created on every read? does camel just change
> endpoint configuration or re-create a new endpoint ?
>
> If you have a good example on how to do dynamic selector with
> camel/activemq, I would love to see it.
>
> I really appreciate all your help.
>
> Thanks
> Kal
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4760387.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
 		 	   		  

Re: Activemq dynamic endpoint configuration

Posted by kal2420 <ka...@cisco.com>.
Ashwin, 

   Thanks, I agree this is a bad approach.  I am a bit confused about how
often configure() method is invoked and when the message would be read from
the queue.  For Example:

 public class TestRouteBuilder extends RouteBuilder {

    public String current_State = "process";

    @Override
    public void configure() throws Exception {

	  String selector = generateSelectorURI(current_state);

        from("activemq:queue:test?selector="+selector)
                .to("log:test")
                .process(new Processor() {
					
					@Override
					public void process(Exchange exchange) throws Exception {
						
						current_State="waiting";
						sendSoapRequest("test");
					}
				});
    }
}

I only want to read and process messages if current_state is “process” ( so
in "waiting" state change selector value so none of the messages would be
read). 

What type of endpoint would camel create based on 
“from(“activemq:queue..”)” ?  ex: polled or scheduled endpoint.

Would the selector uri get re-created on every read? does camel just change
endpoint configuration or re-create a new endpoint ? 

If you have a good example on how to do dynamic selector with
camel/activemq, I would love to see it. 

I really appreciate all your help. 

Thanks
Kal


--
View this message in context: http://camel.465427.n5.nabble.com/Activemq-dynamic-endpoint-configuration-tp4749853p4760387.html
Sent from the Camel - Users mailing list archive at Nabble.com.