camel change route policy at runtime via jmx - apache-camel

is it possible to change at runtime the route policy? for instance, if i have the code below
CronScheduledRoutePolicy startPolicy = new CronScheduledRoutePolicy();
startPolicy.setRouteStartTime("* 0 * * * ?");
startPolicy.setRouteStopTime("* 30 * * * ?");
from("direct:foo").routeId("myRoute").routePolicy(startPolicy).autoStartup(false).to("does://not-matter");
I would like to change the cron parameters during the camel execution. In JConsole I can just access to the getRoutePolicyList which returns
CronScheduledRoutePolicy(0x6dc7efb5)
Is it possible in some way access to the startPolicy object and re-instantiate it with a new value? Have I extend the mbean class of camel with some getter and setters?

No not out of the box. But yeah it would be a nice new feature to register the CronScheduledRoutePolicy as a JMX MBean so people can adjust it at runtime with JMX.
I have logged a ticket: https://issues.apache.org/jira/browse/CAMEL-6334
What you can do is to stop the route. And then adjust the startPolicy settings, and then start the route again.
There is JMX operations for starting and stopping routes. What you may need is to expose some JMX operations to adjust the cron policy.

I managed to do this using hawt.io. But for this to work, you need to upgrade to Camel version 2.13.0.
Using hawt.io, you can change cron expressions at runtime in a very user-friendly way.

Related

restarting a route initialized with File component does not poll the existing files again

Thanks to JMX (java console), I try to restart a route with a file component consumer endpoint.
from("file:<some dir>?noop=true")
I am using the wiretap pattern to record the intermediate data transformation through other files endpoint.
On first start of the camel application, everything is fine, and all the files already present in the input directory are polled and processed.
But when I try to restart the route thanks to jmx, nothing happens.
I try to manually removed .camel directory - created by I guess the default FileIdempotentRepository - before restarting the route, in vain.
I also tried to change the kind of IdempotentRepository with a MemoryIdempotentRepository :
from("file:<somedir>?noop=true").idempotentConsumer(header("CamelFileName"), MemoryIdempotentRepository.memoryIdempotentRepository(1000))
Even if I trigger the clear() operation of this MemoryIdempotentRepository before restarting the route in java console, nothing is polled from the input directory after restarting.
If I add a file, it works. Everything behaves like if there is a persistent history of the files already polled once.
I wonder if the use of the option "noop=true" creates an unmanaged idempotent repository I cannot control with jmx.
If true, the file is not moved or deleted in any way. This option is
good for readonly data, or for ETL type requirements. If noop=true,
Camel will set idempotent=true as well, to avoid consuming the same
files over and over again.
Any idea ?
(i am using camel-core 2.21)
I found the solution to my issue.
I made a bad use of idempotentConsumer; I needed to initialize the endpoint idempotent consumer inside the endpoint URI parameters list.
First, create an entry in a bean registry:
registry.put("myIdempotentRepository", MemoryIdempotentRepository.memoryIdempotentRepository(1000));
Then, refer to this idempotentRepository in the endpoint:
from("file:<somedire>noop=true&initialDelay=10&delay=1000&idempotentRepository=#myIdempotentRepository")
By doing this, GenericFileEndPoint:
will not create a default idempotentRepository
will add the idempotentRepository given in options of the endpoint to the services of the camel context. This means that it will be possible to manage it thanks to JMX
I think it would be useful to be allowed to manage the default idempotent repository in the FileEndPoint class of camel-core.

How to expose Hystrix jmx for Prometheus

I'm new to Hystrix and I just created my first Hystrix Commands. The commands are being created and executed in a loop so the metrics data should have being registered. I am using the servo metrics publisher as follows:
HystrixPlugins.getInstance()
.registerMetricsPublisher(HystrixServoMetricsPublisher.getInstance());
EDIT:
Looking at the JConsole I found the related metrics definition as follows in the link:
jconsole
I am not using spring, eureka, servo to read data and run the app.
I would like to know how to expose this data in a way that prometheus can read. I tried hystrix-prometheus, but the documentation is not helpful when it is about where the metrics are being exposed, how to get them or check the them.
In order to retrieve Hystrix metrics, you'll first need to get Prometheus' Java Simple Client up and running. The setup depends on your environment. Independent of your environment the result should be a URL where you can retrieve i.e. simple Java metrics.
Once that it up and running, you can use the line
HystrixPrometheusMetricsPublisher.register("application_name");
to register the additional Hystrix metrics. They will be served by the same URL. Please note that you will see Hystrix metrics only after the first call of a Hystrix enabled command.

How to Register Solr with Eureka

I have 2 Spring apps ("client-app" and "service-app") that are already registered to Eureka (and talk via Feign Client). However, I have to talk to an instance of Solr and I'm forced to hard-code the IP address in the properties file. I would much rather not do this and use Eureka for service-discovery.
Question: Is there a way/plugin to have solr register itself with Eureka, so that clients can then discover it (even if it's programmatically via a start-up listener or some sort)?
I've looked at the solr API and it doesn't seem to have lifecycle listener (onStartUp or onShutdown hooks)
You would need a Solr Plugin for this, which is SolrCore aware. That interface method inform is called anytime something interesting happens with a core. Within the implementation of the inform method you would need to register/deregister as a client.
Then you would need to add it to your Solr (Cloud) instance. After that and proper configuration of your plugin, it should work.

Apache camel Quartz endpoints : rescheduling at runtime

Is it possible to change cron expression of camel quartzendpoint at runtime using jmx or so ?
You can update the route itself (including configuration of the quartz endpoint). As an example you can see how Camel plugin of Hawt.io (http://hawt.io/plugins/camel/) does it
No, but you could experiment with CamelContext and see if you can add new routes at runtime.

Reconfiguring Apache Camel route parameters at runtime

I have aggregation configured in my code:
.aggregate(new BodyAggregationStrategy())
.constant(true)
.completionSize(1000) // Static value
.completionTimeout(300) // Static value
After I have started the Apache Camel context is it possible to change various parameters like completionSize and completionTimeout values?
When context is running a lot of data are transfering throught it and I want to increase some parameters like queue size and so on.
What you could do, is via the CameContext
stop the route
remove the route
add the route with new parameters
start the route
Have you tried to connect via JMX and see if those parameters can be configured?

Resources