Can we register Managed Routes,Managed Processors and other ManagedBeans of the camelcontext from the CamlTestSupport class.So that we can see the JMX statistics of the routes and processors of camelTestSupport's camel context.If we can register,how to do it?
Yes override the useJmx method and return true.
https://github.com/apache/camel/blob/master/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java#L440
Then when jmx is enabled then Camel will enlist all those mbeans during testing.
There is a few unit tests we enable jmx when testing with blueprint here, you can take a look at
https://github.com/apache/camel/tree/master/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/management
Related
How transacted() in camel DSL is related to transacted="true" of JMSComponent.
Will that make any sense, if transacted property of JMSComponent is set to "true" along with transacted() in camel DSL ?
transacted="true" in JMS component configuration makes your JMS consumer transacted. So this is required if you want to make sure you don't lose messages.
However, you have multiple options to enable transactions (see the Camel docs for details).
Use local JMS transactions
Use your own Spring transaction manager
The Camel DSL transacted() is only necessary if you go with the second option, it references a SpringTransactionPolicy (for example PROPAGATION_REQUIRED). If it is present in your route, Camel is looking for a Spring transaction manager to use.
If you use option 1 (what is simpler in configuration and perfectly suitable if you only talk to a single JMS broker), you don't need the Camel DSL transacted() and your JMS consumer routes are nevertheless transactional.
Addition due to comments
To use option 1, you only have to set transacted="true" and lazyCreateTransactionManager="false" on your Camel ActiveMQComponent. You must not configure a Spring transaction manager (if you do, you end up with two tx managers!)
If you want to be transactional between multiple JMS brokers or a broker and a Database, you would either need XA transactions or you have to implement compensation logic to handle the edge cases when using simple transactions with each system involved.
I'm new to Camel and bit confused between CamelContext and Registry.
As far as I know that CamelContext is the base object like ApplicationContext in Spring that is used for add routes and maintains the camel life cycle.
Also we got the Registry object from CamelContext but not sure what is the main purpose of this registry.
My intention is to add the component in the context/registry so that JNDIBind can look up the components.
CamelContext: Kind of Camel Runtime that keeps everything in Camel together, e.g.: Endpoints, TypeConverter, Routes, Components and Registry(!).
Registry: allows you to lookup beans, which by default will be JNDI beans. If you use the spring integration it will be Spring's ApplicationContext.
Generally camel when used with spring makes use of the ApplicationContextRegistry to lookup components, endpoints etc with the name of the bean defined in spring-bean.xml file. In places where we need to use JNDIRegistry we would have to add that registry when creating the CamelContext. This is used in places where JNDI objects are shared accross multiple JVMs where JNDI is the best solution.
Please see different types of registry implementation for camel: camel registries
I like to monitoring Camel 2.15.2 with Decanter 1.0.0 into Apache Karaf 3.0.3. I get statistics (MaxProcessingTime, LastProcessingTime...) but I can't reset these counters.
How we can reset statistics in Apache Camel?
I typically don't recommend resetting the jmx statistics, but you can do that by calling the reset method in the jmx Operations for that particular stat tracker. If you go to the jsconsole and open up the jmx view and drill down to a particular route or processor under Operations you will find the reset method.
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.
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.