You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Daniel Spaven <da...@gmail.com> on 2011/07/06 15:15:52 UTC

Removing routes programmatically

Hi,

I've been having some problems removing routes programmatically. My routes
use camels CBR pattern to route JMS messages. I remove them using the code:

context.stopRoute(routeIDString);
context.removeRoute(routeIDString);

Now the problem is not that the route is not removed it is, but that it
appears to stop other routes in the same camel context from working.

Now I've tested it using the following camel-core and camel-jms versions:

2.5.0 - Works
2.6.0 - Works
2.7.0 - Fails: Existing routes don't work after a route is removed. However
new routes added will still work. JMS consumer for old unremoved routes
still active but messages never get consumed. The route state from JMX of
the not working routes are still "Started"
2.7.1 - Fails in same way
2.7.2 - Fails in same way

N:B Stopping and starting the same route seems to work fine. It's when a
route is stopped and then removed that the problems appear to occur.

Any ideas? user error or bug?

Cheers,

Dan

Re: Removing routes programmatically

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

Please find a Jira link to the issue attached below.
https://issues.apache.org/jira/browse/CAMEL-4179
https://issues.apache.org/jira/browse/CAMEL-4179 

Please add yourself as a watcher to the issue. We will release a fix
shortly.

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/Removing-routes-programmatically-tp4556741p4557040.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Removing routes programmatically

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jul 6, 2011 at 3:15 PM, Daniel Spaven <da...@gmail.com> wrote:
> Hi,
>
> I've been having some problems removing routes programmatically. My routes
> use camels CBR pattern to route JMS messages. I remove them using the code:
>
> context.stopRoute(routeIDString);
> context.removeRoute(routeIDString);
>
> Now the problem is not that the route is not removed it is, but that it
> appears to stop other routes in the same camel context from working.
>
> Now I've tested it using the following camel-core and camel-jms versions:
>
> 2.5.0 - Works
> 2.6.0 - Works
> 2.7.0 - Fails: Existing routes don't work after a route is removed. However
> new routes added will still work. JMS consumer for old unremoved routes
> still active but messages never get consumed. The route state from JMX of
> the not working routes are still "Started"
> 2.7.1 - Fails in same way
> 2.7.2 - Fails in same way
>
> N:B Stopping and starting the same route seems to work fine. It's when a
> route is stopped and then removed that the problems appear to occur.
>
> Any ideas? user error or bug?
>

Can you post your route that is causing the trouble for you?

I cannot reproduce the issue with 2 routes using seda endpoints on trunk.


> Cheers,
>
> Dan
>



-- 
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: Removing routes programmatically

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Jul 7, 2011 at 2:56 PM, Daniel Spaven <da...@gmail.com> wrote:
> Hey chaps,
>
> Just had another look at this and made some progress.
>
> Now my routes were from JMS to JMS and not with two inputs.
>
> However that did get me thinking because I was testing CBR routes consuming
> from the same JMS topic. When CBR routes are consuming off different topics
> it works fine. Here's my logs of the two scenarios:

Are you using durable topics?

And when you have multiple clients consuming from the same JMS topic,
do you have an unique client id configured?



>
> N:B: Both scenarios show me triggering two routes, removing one and then
> attempting to trigger the remaining route.
>
> 2 Routes consuming from the same topic name:
> ----------------------------------------------------------------------
> 2011-07-07 12:37:26,546 [Camel (camel-1) thread #0 - JmsConsumer[dansTopic]]
> INFO  bt.cbrComponent.model.CBRRouteBuilder - routing using route id: 1
> 2011-07-07 12:37:26,547 [Camel (camel-1) thread #1 - JmsConsumer[dansTopic]]
> INFO  bt.cbrComponent.model.CBRRouteBuilder - routing using route id: 2
> 2011-07-07 12:37:55,778 [qtp17829242-10] INFO  bt.cbrComponent.web.Routes -
> ------------- Deleting route id: 1 ---------------------
> 2011-07-07 12:37:55,972 [qtp17829242-10] INFO
> org.apache.camel.impl.DefaultShutdownStrategy - Starting to graceful
> shutdown 1 routes (timeout 300 seconds)
> 2011-07-07 12:37:55,975 [Camel (camel-1) thread #2 - ShutdownTask] DEBUG
> org.apache.camel.impl.DefaultShutdownStrategy - There are 1 routes to
> shutdown
> 2011-07-07 12:37:55,976 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
> org.apache.camel.impl.DefaultShutdownStrategy - Shutting down route: 1 with
> options [Default,CompleteCurrentTaskOnly]
> 2011-07-07 12:37:55,976 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
> org.apache.camel.impl.DefaultShutdownStrategy - Suspending:
> Consumer[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:37:55,977 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
> org.apache.camel.impl.DefaultShutdownStrategy - Suspend complete for:
> Consumer[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:37:55,977 [Camel (camel-1) thread #2 - ShutdownTask] DEBUG
> org.apache.camel.impl.DefaultShutdownStrategy - Route: 1 suspended and
> shutdown deferred, was consuming from:
> Endpoint[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:37:55,978 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
> org.apache.camel.impl.DefaultShutdownStrategy - Shutting down:
> Consumer[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:37:56,565 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
> org.apache.camel.impl.DefaultShutdownStrategy - Shutdown complete for:
> Consumer[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:37:56,566 [Camel (camel-1) thread #2 - ShutdownTask] INFO
> org.apache.camel.impl.DefaultShutdownStrategy - Route: 1 shutdown complete,
> was consuming from: Endpoint[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:37:56,566 [qtp17829242-10] INFO
> org.apache.camel.impl.DefaultShutdownStrategy - Graceful shutdown of 1
> routes completed in 0 seconds
> 2011-07-07 12:37:56,567 [qtp17829242-10] INFO
> org.apache.camel.impl.DefaultCamelContext - Route: 1 stopped, was consuming
> from: Endpoint[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:37:56,570 [qtp17829242-10] INFO
> org.apache.camel.impl.DefaultCamelContext - Route: 1 shutdown and removed,
> was consuming from: Endpoint[dansJmsComponent://topic:dansTopic]
>
>
> 2 routes consuming from different topic names:
> ---------------------------------------------------------------------
> 2011-07-07 12:43:36,221 [Camel (camel-1) thread #1 -
> JmsConsumer[dansTopicExtra]] INFO  bt.cbrComponent.model.CBRRouteBuilder -
> routing using route id: 2
> 2011-07-07 12:43:36,224 [Camel (camel-1) thread #0 - JmsConsumer[dansTopic]]
> INFO  bt.cbrComponent.model.CBRRouteBuilder - routing using route id: 1
> 2011-07-07 12:43:53,310 [qtp17829242-10] INFO  bt.cbrComponent.web.Routes -
> ------------- Deleting route id: 1 ---------------------
> 2011-07-07 12:43:53,504 [qtp17829242-10] INFO
> org.apache.camel.impl.DefaultShutdownStrategy - Starting to graceful
> shutdown 1 routes (timeout 300 seconds)
> 2011-07-07 12:43:53,507 [Camel (camel-1) thread #2 - ShutdownTask] DEBUG
> org.apache.camel.impl.DefaultShutdownStrategy - There are 1 routes to
> shutdown
> 2011-07-07 12:43:53,507 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
> org.apache.camel.impl.DefaultShutdownStrategy - Shutting down route: 1 with
> options [Default,CompleteCurrentTaskOnly]
> 2011-07-07 12:43:53,508 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
> org.apache.camel.impl.DefaultShutdownStrategy - Suspending:
> Consumer[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:43:53,509 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
> org.apache.camel.impl.DefaultShutdownStrategy - Suspend complete for:
> Consumer[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:43:53,509 [Camel (camel-1) thread #2 - ShutdownTask] DEBUG
> org.apache.camel.impl.DefaultShutdownStrategy - Route: 1 suspended and
> shutdown deferred, was consuming from:
> Endpoint[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:43:53,509 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
> org.apache.camel.impl.DefaultShutdownStrategy - Shutting down:
> Consumer[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:43:54,250 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
> org.apache.camel.impl.DefaultShutdownStrategy - Shutdown complete for:
> Consumer[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:43:54,250 [Camel (camel-1) thread #2 - ShutdownTask] INFO
> org.apache.camel.impl.DefaultShutdownStrategy - Route: 1 shutdown complete,
> was consuming from: Endpoint[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:43:54,250 [qtp17829242-10] INFO
> org.apache.camel.impl.DefaultShutdownStrategy - Graceful shutdown of 1
> routes completed in 0 seconds
> 2011-07-07 12:43:54,252 [qtp17829242-10] INFO
> org.apache.camel.impl.DefaultCamelContext - Route: 1 stopped, was consuming
> from: Endpoint[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:43:54,252 [qtp17829242-10] INFO
> org.apache.camel.impl.DefaultCamelContext - Route: 1 shutdown and removed,
> was consuming from: Endpoint[dansJmsComponent://topic:dansTopic]
> 2011-07-07 12:44:10,011 [ActiveMQ Task-5] INFO
> org.apache.activemq.transport.failover.FailoverTransport - Successfully
> connected to tcp://localhost:61616
> 2011-07-07 12:44:10,077 [Camel (camel-1) thread #1 -
> JmsConsumer[dansTopicExtra]] INFO  bt.cbrComponent.model.CBRRouteBuilder -
> routing using route id: 2
>
> Hope this helps,
>
> Dan
>



-- 
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: Removing routes programmatically

Posted by Manohar Shenoy <ma...@persistent.com>.
From what we can make out, we are still seeing this issue in the latest
version of Camel. One of the associates I work with has posted a related
post
http://camel.465427.n5.nabble.com/Cannot-stop-multiple-route-td5783094.html.
Could someone kindly respond if this is still an issue?



--
View this message in context: http://camel.465427.n5.nabble.com/Removing-routes-programmatically-tp4556741p5783160.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Removing routes programmatically

Posted by "ladislav.lengyel" <la...@siemens.com>.
Hi,

it seems I found the same issue as Daniel described but for the queues.

I modified the unit test from Claus (CAMEL-4179) and it seems the issue is
producible.

See the unit test in the attachment.

My Camel version is 2.10.3

Could you please check it?

Thanks,
Regards,
Laci

TwoConsumerOnTheSameQueueTest.java
<http://camel.465427.n5.nabble.com/file/n5727523/TwoConsumerOnTheSameQueueTest.java>  



--
View this message in context: http://camel.465427.n5.nabble.com/Removing-routes-programmatically-tp4556741p5727523.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Removing routes programmatically

Posted by Daniel Spaven <da...@gmail.com>.
Okay that's nice to hear, I'll download when fixed.

Thanks!

On Fri, Jul 8, 2011 at 11:52 AM, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> Okay i have fixed the issue. I created a new ticket with a better
> description of the real issue
> https://issues.apache.org/jira/browse/CAMEL-4194
>
> The fix will be in Camel 2.8. You are welcome to test with latest
> source code from trunk or the 2.8-SNAPSHOT when its updated.
> http://camel.apache.org/download
>
> On Fri, Jul 8, 2011 at 12:03 PM, Claus Ibsen <cl...@gmail.com>
> wrote:
> > Hi
> >
> > I have reproduced the issue in camel-jms in an unit test. I will try
> > to see what can be done.
> >
> > On Fri, Jul 8, 2011 at 11:37 AM, Daniel Spaven <da...@gmail.com>
> wrote:
> >> Claus,
> >>
> >> Yes that's it. Here's the URI's of 2 routes I just tested and failed. So
> >> Destinations different but consuming from the same topic.
> >>
> >> Route 1
> >> -----------
> >> from(jmsComponent:topic:dansTopic)
> >> to(activemq:topic:TMLP1)
> >> to(activemq:topic:TMLP2)
> >> to(activemq:topic:TMLP3)
> >> to(activemq:topic:TMLP4)
> >>
> >> Route 2
> >> ------------
> >> from(jmsComponent:topic:dansTopic)
> >> to(activemq:topic:TMLM25)
> >> to(activemq:topic:TMLM1)
> >> to(activemq:topic:TMLM40)
> >> to(activemq:topic:TMLA12)
> >> to(activemq:topic:TMLA13)
> >>
> >
> >
> >
> > --
> > 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: Removing routes programmatically

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

Okay i have fixed the issue. I created a new ticket with a better
description of the real issue
https://issues.apache.org/jira/browse/CAMEL-4194

The fix will be in Camel 2.8. You are welcome to test with latest
source code from trunk or the 2.8-SNAPSHOT when its updated.
http://camel.apache.org/download

On Fri, Jul 8, 2011 at 12:03 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> I have reproduced the issue in camel-jms in an unit test. I will try
> to see what can be done.
>
> On Fri, Jul 8, 2011 at 11:37 AM, Daniel Spaven <da...@gmail.com> wrote:
>> Claus,
>>
>> Yes that's it. Here's the URI's of 2 routes I just tested and failed. So
>> Destinations different but consuming from the same topic.
>>
>> Route 1
>> -----------
>> from(jmsComponent:topic:dansTopic)
>> to(activemq:topic:TMLP1)
>> to(activemq:topic:TMLP2)
>> to(activemq:topic:TMLP3)
>> to(activemq:topic:TMLP4)
>>
>> Route 2
>> ------------
>> from(jmsComponent:topic:dansTopic)
>> to(activemq:topic:TMLM25)
>> to(activemq:topic:TMLM1)
>> to(activemq:topic:TMLM40)
>> to(activemq:topic:TMLA12)
>> to(activemq:topic:TMLA13)
>>
>
>
>
> --
> 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: Removing routes programmatically

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

I have reproduced the issue in camel-jms in an unit test. I will try
to see what can be done.

On Fri, Jul 8, 2011 at 11:37 AM, Daniel Spaven <da...@gmail.com> wrote:
> Claus,
>
> Yes that's it. Here's the URI's of 2 routes I just tested and failed. So
> Destinations different but consuming from the same topic.
>
> Route 1
> -----------
> from(jmsComponent:topic:dansTopic)
> to(activemq:topic:TMLP1)
> to(activemq:topic:TMLP2)
> to(activemq:topic:TMLP3)
> to(activemq:topic:TMLP4)
>
> Route 2
> ------------
> from(jmsComponent:topic:dansTopic)
> to(activemq:topic:TMLM25)
> to(activemq:topic:TMLM1)
> to(activemq:topic:TMLM40)
> to(activemq:topic:TMLA12)
> to(activemq:topic:TMLA13)
>



-- 
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: Removing routes programmatically

Posted by Daniel Spaven <da...@gmail.com>.
Claus,

Yes that's it. Here's the URI's of 2 routes I just tested and failed. So
Destinations different but consuming from the same topic.

Route 1
-----------
from(jmsComponent:topic:dansTopic)
to(activemq:topic:TMLP1)
to(activemq:topic:TMLP2)
to(activemq:topic:TMLP3)
to(activemq:topic:TMLP4)

Route 2
------------
from(jmsComponent:topic:dansTopic)
to(activemq:topic:TMLM25)
to(activemq:topic:TMLM1)
to(activemq:topic:TMLM40)
to(activemq:topic:TMLA12)
to(activemq:topic:TMLA13)

Re: Removing routes programmatically

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Jul 8, 2011 at 8:56 AM, Daniel Spaven <da...@gmail.com> wrote:
> Hey Claus, Ashwin,
>
> I haven't got any access to my development environment right now. But i can
> tell you by memory that the topic is not durable and the durable topic name
> and client id is not set.
>
> Also Ashwin regarding the test; based on what i observed when looking at the
> runtime route attributes on JMX (as stated in my first post). The test you
> ran would not catch the problem. After removing a route my other routes
> would still be running and have the status of "started", however they
> wouldn't actually be working. They would not consume and route JMS messages
> as they should do and were doing before i removed a route.
>

Can you post the actual endpoint uris of the routes. I suspect you may
have duplicate uris, and

<route id="a">
   <from uri="jms:topic:foo"/>
   ...
</route>

<route id="b">
   <from uri="jms:topic:foo"/>
   ...
</route>

And then if you stop route A, then somehow the topic consumer in route
B gets stopped as well.


> On Thu, Jul 7, 2011 at 4:42 PM, Ashwin Karpe <ak...@fusesource.com> wrote:
>
>> Hi Daniel,
>>
>> I am finding it hard to see an issue when I run the following test. While I
>> am not using JMS, I do have the same consumer setup under a different
>> routeId. I find that following a run of this test that routeId "bar" is
>> still up and running.
>>
>> The line assertNull(context.getRouteStatus("bar")); fails as expected...
>>
>> I have not tried JMS and whether there are any side-effects tied to this.
>> Can't see anything wrong when I run SEDA with multiple consumers.
>>
>> Cheers,
>>
>> Ashwin...
>>
>>
>> ----------------------------------------------------------------------------------------------------------
>>
>> /**
>>  * Licensed to the Apache Software Foundation (ASF) under one or more
>>  * contributor license agreements.  See the NOTICE file distributed with
>>  * this work for additional information regarding copyright ownership.
>>  * The ASF licenses this file to You under the Apache License, Version 2.0
>>  * (the "License"); you may not use this file except in compliance with
>>  * the License.  You may obtain a copy of the License at
>>  *
>>  *      http://www.apache.org/licenses/LICENSE-2.0
>>  *
>>  * Unless required by applicable law or agreed to in writing, software
>>  * distributed under the License is distributed on an "AS IS" BASIS,
>>  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>>  * See the License for the specific language governing permissions and
>>  * limitations under the License.
>>  */
>> package org.apache.camel.impl;
>>
>> import org.apache.camel.ContextTestSupport;
>> import org.apache.camel.ServiceStatus;
>> import org.apache.camel.builder.RouteBuilder;
>> import org.apache.camel.component.mock.MockEndpoint;
>>
>> /**
>>  * @version
>>  */
>> public class RouteRemoveTest extends ContextTestSupport {
>>
>>    public void testRemove() throws Exception {
>>        MockEndpoint mock = getMockEndpoint("mock:result");
>>        mock.expectedBodiesReceived("A");
>>
>>        template.sendBody("seda:foo", "A");
>>
>>        assertMockEndpointsSatisfied();
>>
>>        assertEquals("Started", context.getRouteStatus("foo").name());
>>        assertEquals("Started", context.getRouteStatus("bar").name());
>>        assertEquals(2, context.getRoutes().size());
>>
>>        // must be stopped so we cant remove
>>        boolean removed = context.removeRoute("foo");
>>        assertFalse(removed);
>>
>>        assertEquals(2, context.getRoutes().size());
>>        assertEquals("Started", context.getRouteStatus("foo").name());
>>        assertEquals("Started", context.getRouteStatus("bar").name());
>>
>>        // remove route then
>>        context.stopRoute("foo");
>>        removed = context.removeRoute("foo");
>>        assertTrue(removed);
>>
>>        assertNull(context.getRouteStatus("bar"));
>>        assertEquals(0, context.getRoutes().size());
>>        assertNull(context.getRouteStatus("foo"));
>>    }
>>
>>    @Override
>>    protected RouteBuilder createRouteBuilder() throws Exception {
>>        return new RouteBuilder() {
>>            @Override
>>            public void configure() throws Exception {
>>
>>
>> from("seda:foo?multipleConsumers=true").routeId("foo").to("log:foo").to("mock:result");
>>
>>
>> from("seda:foo?multipleConsumers=true").routeId("bar").to("log:foo").to("mock:result");
>>             }
>>        };
>>    }
>> }
>>
>> -----
>> ---------------------------------------------------------
>> 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/Removing-routes-programmatically-tp4556741p4561468.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: Removing routes programmatically

Posted by Daniel Spaven <da...@gmail.com>.
Hey Claus, Ashwin,

I haven't got any access to my development environment right now. But i can
tell you by memory that the topic is not durable and the durable topic name
and client id is not set.

Also Ashwin regarding the test; based on what i observed when looking at the
runtime route attributes on JMX (as stated in my first post). The test you
ran would not catch the problem. After removing a route my other routes
would still be running and have the status of "started", however they
wouldn't actually be working. They would not consume and route JMS messages
as they should do and were doing before i removed a route.

On Thu, Jul 7, 2011 at 4:42 PM, Ashwin Karpe <ak...@fusesource.com> wrote:

> Hi Daniel,
>
> I am finding it hard to see an issue when I run the following test. While I
> am not using JMS, I do have the same consumer setup under a different
> routeId. I find that following a run of this test that routeId "bar" is
> still up and running.
>
> The line assertNull(context.getRouteStatus("bar")); fails as expected...
>
> I have not tried JMS and whether there are any side-effects tied to this.
> Can't see anything wrong when I run SEDA with multiple consumers.
>
> Cheers,
>
> Ashwin...
>
>
> ----------------------------------------------------------------------------------------------------------
>
> /**
>  * Licensed to the Apache Software Foundation (ASF) under one or more
>  * contributor license agreements.  See the NOTICE file distributed with
>  * this work for additional information regarding copyright ownership.
>  * The ASF licenses this file to You under the Apache License, Version 2.0
>  * (the "License"); you may not use this file except in compliance with
>  * the License.  You may obtain a copy of the License at
>  *
>  *      http://www.apache.org/licenses/LICENSE-2.0
>  *
>  * Unless required by applicable law or agreed to in writing, software
>  * distributed under the License is distributed on an "AS IS" BASIS,
>  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>  * See the License for the specific language governing permissions and
>  * limitations under the License.
>  */
> package org.apache.camel.impl;
>
> import org.apache.camel.ContextTestSupport;
> import org.apache.camel.ServiceStatus;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.mock.MockEndpoint;
>
> /**
>  * @version
>  */
> public class RouteRemoveTest extends ContextTestSupport {
>
>    public void testRemove() throws Exception {
>        MockEndpoint mock = getMockEndpoint("mock:result");
>        mock.expectedBodiesReceived("A");
>
>        template.sendBody("seda:foo", "A");
>
>        assertMockEndpointsSatisfied();
>
>        assertEquals("Started", context.getRouteStatus("foo").name());
>        assertEquals("Started", context.getRouteStatus("bar").name());
>        assertEquals(2, context.getRoutes().size());
>
>        // must be stopped so we cant remove
>        boolean removed = context.removeRoute("foo");
>        assertFalse(removed);
>
>        assertEquals(2, context.getRoutes().size());
>        assertEquals("Started", context.getRouteStatus("foo").name());
>        assertEquals("Started", context.getRouteStatus("bar").name());
>
>        // remove route then
>        context.stopRoute("foo");
>        removed = context.removeRoute("foo");
>        assertTrue(removed);
>
>        assertNull(context.getRouteStatus("bar"));
>        assertEquals(0, context.getRoutes().size());
>        assertNull(context.getRouteStatus("foo"));
>    }
>
>    @Override
>    protected RouteBuilder createRouteBuilder() throws Exception {
>        return new RouteBuilder() {
>            @Override
>            public void configure() throws Exception {
>
>
> from("seda:foo?multipleConsumers=true").routeId("foo").to("log:foo").to("mock:result");
>
>
> from("seda:foo?multipleConsumers=true").routeId("bar").to("log:foo").to("mock:result");
>             }
>        };
>    }
> }
>
> -----
> ---------------------------------------------------------
> 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/Removing-routes-programmatically-tp4556741p4561468.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Removing routes programmatically

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi Daniel,

I am finding it hard to see an issue when I run the following test. While I
am not using JMS, I do have the same consumer setup under a different
routeId. I find that following a run of this test that routeId "bar" is
still up and running.

The line assertNull(context.getRouteStatus("bar")); fails as expected...

I have not tried JMS and whether there are any side-effects tied to this.
Can't see anything wrong when I run SEDA with multiple consumers.

Cheers,

Ashwin...

----------------------------------------------------------------------------------------------------------

/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.impl;

import org.apache.camel.ContextTestSupport;
import org.apache.camel.ServiceStatus;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;

/**
 * @version 
 */
public class RouteRemoveTest extends ContextTestSupport {

    public void testRemove() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedBodiesReceived("A");

        template.sendBody("seda:foo", "A");
        
        assertMockEndpointsSatisfied();

        assertEquals("Started", context.getRouteStatus("foo").name());
        assertEquals("Started", context.getRouteStatus("bar").name());
        assertEquals(2, context.getRoutes().size());

        // must be stopped so we cant remove
        boolean removed = context.removeRoute("foo");
        assertFalse(removed);

        assertEquals(2, context.getRoutes().size());
        assertEquals("Started", context.getRouteStatus("foo").name());
        assertEquals("Started", context.getRouteStatus("bar").name());

        // remove route then
        context.stopRoute("foo");
        removed = context.removeRoute("foo");
        assertTrue(removed);
        
        assertNull(context.getRouteStatus("bar"));
        assertEquals(0, context.getRoutes().size());
        assertNull(context.getRouteStatus("foo"));
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
               
from("seda:foo?multipleConsumers=true").routeId("foo").to("log:foo").to("mock:result");
               
from("seda:foo?multipleConsumers=true").routeId("bar").to("log:foo").to("mock:result");
            }
        };
    }
}

-----
---------------------------------------------------------
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/Removing-routes-programmatically-tp4556741p4561468.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Removing routes programmatically

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi Daniel,

Thanks for the input. Will check this out. Stay tuned.

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/Removing-routes-programmatically-tp4556741p4561373.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Removing routes programmatically

Posted by Daniel Spaven <da...@gmail.com>.
Hey chaps,

Just had another look at this and made some progress.

Now my routes were from JMS to JMS and not with two inputs.

However that did get me thinking because I was testing CBR routes consuming
from the same JMS topic. When CBR routes are consuming off different topics
it works fine. Here's my logs of the two scenarios:

N:B: Both scenarios show me triggering two routes, removing one and then
attempting to trigger the remaining route.

2 Routes consuming from the same topic name:
----------------------------------------------------------------------
2011-07-07 12:37:26,546 [Camel (camel-1) thread #0 - JmsConsumer[dansTopic]]
INFO  bt.cbrComponent.model.CBRRouteBuilder - routing using route id: 1
2011-07-07 12:37:26,547 [Camel (camel-1) thread #1 - JmsConsumer[dansTopic]]
INFO  bt.cbrComponent.model.CBRRouteBuilder - routing using route id: 2
2011-07-07 12:37:55,778 [qtp17829242-10] INFO  bt.cbrComponent.web.Routes -
------------- Deleting route id: 1 ---------------------
2011-07-07 12:37:55,972 [qtp17829242-10] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Starting to graceful
shutdown 1 routes (timeout 300 seconds)
2011-07-07 12:37:55,975 [Camel (camel-1) thread #2 - ShutdownTask] DEBUG
org.apache.camel.impl.DefaultShutdownStrategy - There are 1 routes to
shutdown
2011-07-07 12:37:55,976 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
org.apache.camel.impl.DefaultShutdownStrategy - Shutting down route: 1 with
options [Default,CompleteCurrentTaskOnly]
2011-07-07 12:37:55,976 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
org.apache.camel.impl.DefaultShutdownStrategy - Suspending:
Consumer[dansJmsComponent://topic:dansTopic]
2011-07-07 12:37:55,977 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
org.apache.camel.impl.DefaultShutdownStrategy - Suspend complete for:
Consumer[dansJmsComponent://topic:dansTopic]
2011-07-07 12:37:55,977 [Camel (camel-1) thread #2 - ShutdownTask] DEBUG
org.apache.camel.impl.DefaultShutdownStrategy - Route: 1 suspended and
shutdown deferred, was consuming from:
Endpoint[dansJmsComponent://topic:dansTopic]
2011-07-07 12:37:55,978 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
org.apache.camel.impl.DefaultShutdownStrategy - Shutting down:
Consumer[dansJmsComponent://topic:dansTopic]
2011-07-07 12:37:56,565 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
org.apache.camel.impl.DefaultShutdownStrategy - Shutdown complete for:
Consumer[dansJmsComponent://topic:dansTopic]
2011-07-07 12:37:56,566 [Camel (camel-1) thread #2 - ShutdownTask] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Route: 1 shutdown complete,
was consuming from: Endpoint[dansJmsComponent://topic:dansTopic]
2011-07-07 12:37:56,566 [qtp17829242-10] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Graceful shutdown of 1
routes completed in 0 seconds
2011-07-07 12:37:56,567 [qtp17829242-10] INFO
org.apache.camel.impl.DefaultCamelContext - Route: 1 stopped, was consuming
from: Endpoint[dansJmsComponent://topic:dansTopic]
2011-07-07 12:37:56,570 [qtp17829242-10] INFO
org.apache.camel.impl.DefaultCamelContext - Route: 1 shutdown and removed,
was consuming from: Endpoint[dansJmsComponent://topic:dansTopic]


2 routes consuming from different topic names:
---------------------------------------------------------------------
2011-07-07 12:43:36,221 [Camel (camel-1) thread #1 -
JmsConsumer[dansTopicExtra]] INFO  bt.cbrComponent.model.CBRRouteBuilder -
routing using route id: 2
2011-07-07 12:43:36,224 [Camel (camel-1) thread #0 - JmsConsumer[dansTopic]]
INFO  bt.cbrComponent.model.CBRRouteBuilder - routing using route id: 1
2011-07-07 12:43:53,310 [qtp17829242-10] INFO  bt.cbrComponent.web.Routes -
------------- Deleting route id: 1 ---------------------
2011-07-07 12:43:53,504 [qtp17829242-10] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Starting to graceful
shutdown 1 routes (timeout 300 seconds)
2011-07-07 12:43:53,507 [Camel (camel-1) thread #2 - ShutdownTask] DEBUG
org.apache.camel.impl.DefaultShutdownStrategy - There are 1 routes to
shutdown
2011-07-07 12:43:53,507 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
org.apache.camel.impl.DefaultShutdownStrategy - Shutting down route: 1 with
options [Default,CompleteCurrentTaskOnly]
2011-07-07 12:43:53,508 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
org.apache.camel.impl.DefaultShutdownStrategy - Suspending:
Consumer[dansJmsComponent://topic:dansTopic]
2011-07-07 12:43:53,509 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
org.apache.camel.impl.DefaultShutdownStrategy - Suspend complete for:
Consumer[dansJmsComponent://topic:dansTopic]
2011-07-07 12:43:53,509 [Camel (camel-1) thread #2 - ShutdownTask] DEBUG
org.apache.camel.impl.DefaultShutdownStrategy - Route: 1 suspended and
shutdown deferred, was consuming from:
Endpoint[dansJmsComponent://topic:dansTopic]
2011-07-07 12:43:53,509 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
org.apache.camel.impl.DefaultShutdownStrategy - Shutting down:
Consumer[dansJmsComponent://topic:dansTopic]
2011-07-07 12:43:54,250 [Camel (camel-1) thread #2 - ShutdownTask] TRACE
org.apache.camel.impl.DefaultShutdownStrategy - Shutdown complete for:
Consumer[dansJmsComponent://topic:dansTopic]
2011-07-07 12:43:54,250 [Camel (camel-1) thread #2 - ShutdownTask] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Route: 1 shutdown complete,
was consuming from: Endpoint[dansJmsComponent://topic:dansTopic]
2011-07-07 12:43:54,250 [qtp17829242-10] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Graceful shutdown of 1
routes completed in 0 seconds
2011-07-07 12:43:54,252 [qtp17829242-10] INFO
org.apache.camel.impl.DefaultCamelContext - Route: 1 stopped, was consuming
from: Endpoint[dansJmsComponent://topic:dansTopic]
2011-07-07 12:43:54,252 [qtp17829242-10] INFO
org.apache.camel.impl.DefaultCamelContext - Route: 1 shutdown and removed,
was consuming from: Endpoint[dansJmsComponent://topic:dansTopic]
2011-07-07 12:44:10,011 [ActiveMQ Task-5] INFO
org.apache.activemq.transport.failover.FailoverTransport - Successfully
connected to tcp://localhost:61616
2011-07-07 12:44:10,077 [Camel (camel-1) thread #1 -
JmsConsumer[dansTopicExtra]] INFO  bt.cbrComponent.model.CBRRouteBuilder -
routing using route id: 2

Hope this helps,

Dan

Re: Removing routes programmatically

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jul 6, 2011 at 4:58 PM, Ashwin Karpe <ak...@fusesource.com> wrote:
> Hi,
>
> You are right. The stopRoute() is responsible for stopping the route from
> the Camel Context.
>
> The removeRoute() however stops the RouteService associated with the route.
> Since the RouteService is associated with a collection of routes, performing
> this operation has an unintended consequence of shutting down the
> RouteServices and removing of other routes managed by the RouteService...
>

The RouteService may seem to have a collection but in reality there
should only be 1 route in there.
That was just how the API back in the days was crafted. The
RouteService may have multuple routes in situations where the route
has multiple inputs.

Daniels does any of your routes have 2+ inputs? eg from("xxx", "yyyy",
"zzzz").to("blah");


What springs to my mind is that stopping a route re-uses the shutdown
strategy to graceful shutdown the route (to avoid loosing inflight
messages etc.). And there may be a side effect of that service to stop
other consumers/routes.

But we need a re-producable test. That helps a lot :)

> This is a bug or at the least an incorrectly named API. I will raise this as
> a bug.
>
> Watch for the Jira link in my following note.
>
> 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/Removing-routes-programmatically-tp4556741p4557011.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: Removing routes programmatically

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

You are right. The stopRoute() is responsible for stopping the route from
the Camel Context.

The removeRoute() however stops the RouteService associated with the route.
Since the RouteService is associated with a collection of routes, performing
this operation has an unintended consequence of shutting down the
RouteServices and removing of other routes managed by the RouteService... 

This is a bug or at the least an incorrectly named API. I will raise this as
a bug.

Watch for the Jira link in my following note.

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/Removing-routes-programmatically-tp4556741p4557011.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Removing routes programmatically

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jul 6, 2011 at 11:25 PM, Daniel Spaven <da...@gmail.com> wrote:
> I understand that it might be hard to debug from this class alone, so if you
> want me to adapt the class and plug in the run-time values that are failing
> in my tests I can do that tomorrow.
>
> Dan
>

Yeah it would be nice with a runtime example, what Camel components do
you use as the input for the route? JMS, File, WebService?

And what are the destinations you send the message to in the CBR when/otherwise?

If you enable TRACE logging on this class
org.apache.camel.impl.DefaultShutdownStrategy

And run a test that fails, then attach the log, that would help. It
logs how it shutdown the route when you stop/remove it.


-- 
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: Removing routes programmatically

Posted by Daniel Spaven <da...@gmail.com>.
I understand that it might be hard to debug from this class alone, so if you
want me to adapt the class and plug in the run-time values that are failing
in my tests I can do that tomorrow.

Dan

Re: Removing routes programmatically

Posted by Daniel Spaven <da...@gmail.com>.
Yeah sure.

I've attached the route.

As you can see it's effectively a template for a CBR route, the values of
which I populate when instantiated.

Its then added to the camel context in the standard way:
context.addRoutes(CBRRouteBuilder)

Cheers,

Dan

On Wed, Jul 6, 2011 at 4:57 PM, Ashwin Karpe <ak...@fusesource.com> wrote:

> Hi Daniel,
>
> Can you please post your route that exhibits this behavior. I am having a
> bit of difficulty reproducing the issue.
>
> I can see the code, however, I do not see a way to trigger this behavior to
> happen.
>
> Thanks & Regards,
>
> 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/Removing-routes-programmatically-tp4556741p4557219.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Removing routes programmatically

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi Daniel,

Can you please post your route that exhibits this behavior. I am having a
bit of difficulty reproducing the issue.

I can see the code, however, I do not see a way to trigger this behavior to
happen.

Thanks & Regards,

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/Removing-routes-programmatically-tp4556741p4557219.html
Sent from the Camel - Users mailing list archive at Nabble.com.