Re: Dynamically restarting consumer routes with changed URI parameters

2019-10-17 Thread Ralf Claussnitzer

Hi everybody,

here is my solution so far. I discovered that we would need to remove 
the existing route and recreate it using its initial RouteDefinition. 
That is at least the way ReloadStrategies are supposed to work. Here is 
some demo code. It restarts a ticker route with random period parameter 
values.


import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.camel.main.Main;
import org.apache.camel.model.RouteDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Properties;
import java.util.Random;

public class DynamicRouteReloadExperiment {

protected final Loggerlog = LoggerFactory.getLogger(getClass());

public static void main(String... args)throws Exception {

Main main =new Main();

Properties props =new Properties();
props.setProperty("period","1500");

PropertiesComponent propertiesComponent =new PropertiesComponent();
propertiesComponent.setOverrideProperties(props);

main.bind("properties", propertiesComponent);

main.addRouteBuilder(new RouteBuilder() {
@Override public void configure()throws Exception {
from("timer:tick?period={{period}}")
.routeId("A")
.log("Tick!");

from("timer:tick?period=8000")
.routeId("B")
.process(exchange -> {
CamelContext camelContext = exchange.getContext();

Random random =new Random();

camelContext.getComponent("properties", 
PropertiesComponent.class)
.getOverrideProperties()
.setProperty("period", String.valueOf(1000 
+ random.nextInt(1000)));

RouteDefinition routeDefinition = 
camelContext.getRouteDefinition("A");
camelContext.removeRouteDefinition(routeDefinition);
camelContext.addRouteDefinition(routeDefinition);
});

}
});

main.run(args);
}

}

IMHO this "hard restart" should be a feature of the ControlBus component 
which can already stop and resume routes.


-Ralf

On 10/16/19 9:28 AM, Ralf Claussnitzer wrote:

Hello all,

is there a way to restart defined routes so that the from() URI gets 
updated?
We have tried several things using the "Controlbus" component, but we 
cannot restart a defined and running route /with changed URI parameters/.


Background (what do we want to achieve):

   We have several Kafka Consumer routes which we want to restart with
   different options depending on other events. In particular we want
   to restart a running route and change the URI parameter "seekTo" to
   trigger reprocessing past events.

While reprocessing Kafka events is our main topic at the moment, we 
imagine that restarting a route and recalculate the consumer URI might 
be useful for other use cases as well. Let us know what you think!


Regards,
Ralf




Re: Dynamically restarting consumer routes with changed URI parameters

2019-10-16 Thread Ralf Claussnitzer

Hi Karsten,

thanks for the swift reply!

How would we setup this "property auto reload" feature?
And why would it restart the existing context?
Can it also just restart the affected routes?

Regards,
Ralf

On 10/16/19 10:43 AM, Karsten Blume wrote:

Hello Ralf,
Use property placeholder for your endpoints, define the property configuration 
as automatically reloadable and change the URI by kafka cmd line, config file 
in etc/ or by JMX.
The context is restarted automatically after URI change.
The property should be changeable also programmatically by your event handler.
Best regards
Karsten

-Original Message-
From: Omar Al-Safi 
Sent: Mittwoch, 16. Oktober 2019 09:58
To: users@camel.apache.org
Subject: Re: Dynamically restarting consumer routes with changed URI parameters

Hi Ralf,

If you have these routes as a RouteBuilder beans, I think you can utilize 
CamelContext APIs such `addRoute` to add the bean dynamically. Of course you 
will need to implement a way to hot reloading of your .class files whenever you 
deem to. You can take a look at this test for an example:
https://github.com/apache/camel/blob/b9a3117f19dd19abd2ea8b789c42c3e86fe4c488/core/camel-core/src/test/java/org/apache/camel/builder/AddRoutesAtRuntimeTest.java

Regards,
Omar

On Wed, 16 Oct 2019 at 09:28, Ralf Claussnitzer < 
ralf.claussnit...@slub-dresden.de> wrote:


Hello all,

is there a way to restart defined routes so that the from() URI gets
updated?
We have tried several things using the "Controlbus" component, but we
cannot restart a defined and running route /with changed URI parameters/.

Background (what do we want to achieve):

 We have several Kafka Consumer routes which we want to restart with
 different options depending on other events. In particular we want
 to restart a running route and change the URI parameter "seekTo" to
 trigger reprocessing past events.

While reprocessing Kafka events is our main topic at the moment, we
imagine that restarting a route and recalculate the consumer URI might
be useful for other use cases as well. Let us know what you think!

Regards,
Ralf




RE: Dynamically restarting consumer routes with changed URI parameters

2019-10-16 Thread Karsten Blume

Hello Ralf,
Use property placeholder for your endpoints, define the property configuration 
as automatically reloadable and change the URI by kafka cmd line, config file 
in etc/ or by JMX.
The context is restarted automatically after URI change.
The property should be changeable also programmatically by your event handler.
Best regards
Karsten

-Original Message-
From: Omar Al-Safi  
Sent: Mittwoch, 16. Oktober 2019 09:58
To: users@camel.apache.org
Subject: Re: Dynamically restarting consumer routes with changed URI parameters

Hi Ralf,

If you have these routes as a RouteBuilder beans, I think you can utilize 
CamelContext APIs such `addRoute` to add the bean dynamically. Of course you 
will need to implement a way to hot reloading of your .class files whenever you 
deem to. You can take a look at this test for an example:
https://github.com/apache/camel/blob/b9a3117f19dd19abd2ea8b789c42c3e86fe4c488/core/camel-core/src/test/java/org/apache/camel/builder/AddRoutesAtRuntimeTest.java

Regards,
Omar

On Wed, 16 Oct 2019 at 09:28, Ralf Claussnitzer < 
ralf.claussnit...@slub-dresden.de> wrote:

> Hello all,
>
> is there a way to restart defined routes so that the from() URI gets 
> updated?
> We have tried several things using the "Controlbus" component, but we 
> cannot restart a defined and running route /with changed URI parameters/.
>
> Background (what do we want to achieve):
>
> We have several Kafka Consumer routes which we want to restart with
> different options depending on other events. In particular we want
> to restart a running route and change the URI parameter "seekTo" to
> trigger reprocessing past events.
>
> While reprocessing Kafka events is our main topic at the moment, we 
> imagine that restarting a route and recalculate the consumer URI might 
> be useful for other use cases as well. Let us know what you think!
>
> Regards,
> Ralf
>
>


Re: Dynamically restarting consumer routes with changed URI parameters

2019-10-16 Thread Omar Al-Safi
Hi Ralf,

If you have these routes as a RouteBuilder beans, I think you can utilize
CamelContext APIs such `addRoute` to add the bean dynamically. Of course
you will need to implement a way to hot reloading of your .class files
whenever you deem to. You can take a look at this test for an example:
https://github.com/apache/camel/blob/b9a3117f19dd19abd2ea8b789c42c3e86fe4c488/core/camel-core/src/test/java/org/apache/camel/builder/AddRoutesAtRuntimeTest.java

Regards,
Omar

On Wed, 16 Oct 2019 at 09:28, Ralf Claussnitzer <
ralf.claussnit...@slub-dresden.de> wrote:

> Hello all,
>
> is there a way to restart defined routes so that the from() URI gets
> updated?
> We have tried several things using the "Controlbus" component, but we
> cannot restart a defined and running route /with changed URI parameters/.
>
> Background (what do we want to achieve):
>
> We have several Kafka Consumer routes which we want to restart with
> different options depending on other events. In particular we want
> to restart a running route and change the URI parameter "seekTo" to
> trigger reprocessing past events.
>
> While reprocessing Kafka events is our main topic at the moment, we
> imagine that restarting a route and recalculate the consumer URI might
> be useful for other use cases as well. Let us know what you think!
>
> Regards,
> Ralf
>
>


Dynamically restarting consumer routes with changed URI parameters

2019-10-16 Thread Ralf Claussnitzer

Hello all,

is there a way to restart defined routes so that the from() URI gets 
updated?
We have tried several things using the "Controlbus" component, but we 
cannot restart a defined and running route /with changed URI parameters/.


Background (what do we want to achieve):

   We have several Kafka Consumer routes which we want to restart with
   different options depending on other events. In particular we want
   to restart a running route and change the URI parameter "seekTo" to
   trigger reprocessing past events.

While reprocessing Kafka events is our main topic at the moment, we 
imagine that restarting a route and recalculate the consumer URI might 
be useful for other use cases as well. Let us know what you think!


Regards,
Ralf