How we can reset statistics in Apache Camel? - apache-camel

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.

Related

Duplication of camel context mbeans after vetoed start

I have an application where I have custom lifecycle strategy for camel context start. This strategy has some logic which checked onCamelStart "event". Let's say it checks if cluster formed or not. If not, VetoCamelContextStartException thrown and thus context not started.
But I got warning with message like "clash of names for camel context" and name with prefix -n is used to register camel context into mbean server. Camel handle duplication in such a way As result I see couple of beans in jmx console.
DefaultManagementLifecycleStrategy is used to register mbeans (added in ManagmentStrategyFactory) and it can unmanage mbeans during onCamelStop.
As result I have next sequence of events which manifest into duplication of mbeans:
Start of Camel Context.
DefaultManagementLifecycleStrategy register all mbeans
CustomLifecycleStrategy puts the veto for start.
DefaultManagementLifecycleStrategy uregister all mbeans when onStop invoked.
Camel context marked as stopped.
Camel context is starting and registration of mbeans repeats.
Start of Camel context is vetoed again
Camel doesn't stop context due to it is already stopped (marked as stopped) and as result all mbeans are still in place.
Camel starts again and duplication of mbeans occurs.
We haven't seen such warning and duplication of mbeans in 2.17.7. Is it some bug in Camel? Or are we doing something wrong conceptually?
I have migrated Camel from 2.17.7 to 2.25.4. I am using Spring Boot and my camel context is defined in xml.

Log apache camel seda queue depth every second via a timer

How can I log actual seda queue depth every second on a timer.
E.g.
from("seda:messageParser?concurrentConsumers=5&size=5000)
.process(messageProcessor)
from("timer://sedaQueueDepthLogger?fixedRate=true")
.to(LOG_SEDA_QUEUE_DEPTH)
What should be LOG_SEDA_QUEUE_DEPTH above to achieve this?
You cannot log it that easily. From a custom processor, you can get the seda endpoint, and from there you have APIs to get the queue, and get the size, which you can then log.
There is also JMX API to find that information.

JMSComponent>transacted=true and transacted() in camel builder

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.

Load01,Load05,Load15 attributes in apache camel jmx returns empty string

I am using Apache Camel (v2.19.1) in a spring boot application. I want to monitor the application with JMX MBeans.
I want to find out the load for a particular 'route' from the class "org.apache.camel.management.mbean.ManagedRoute" attributes Load01, Load05 etc...
I get empty string as values for Load attributes. The statistics is already enabled.
Kindly help.
Thank you,
You need to turn this on. You can find details in the JMX documentation how to turn on load statistics: http://camel.apache.org/camel-jmx.html, eg set the loadStatisticsEnabled=true

Set TTL Apache Camel JAva DSL

How do you set the TTL for a message when using Java DSL?
I have something like this:
...
from ("timer:something?delay=3000&period=15000")
...
.to("{{some.property}}")
.end()
...
I want to set a time to live on the message being sent.
I ended up setting the JMSExpiration header field of the messages being created similar to the following
.setHeader("JMSExpiration", constant(System.currentTimeMillis() + 1000))
We are using Apache ActiveMQ 5.7.
I assume TTL means Time to Live.
In Camel this is component specific how they deal with this. Some components support this, and others do not.
You should check the documentation for the component you use, what it supports.
If you use JMS component then it has the timeToLive option as documented: http://camel.apache.org/jms
And mind about the problem with "client and server clock's can be out of sync". There is some details on the Camel JMS page. Some message brokers has ways to sync the clocks, such as Apache ActiveMQ with its timestamp plugin: http://activemq.apache.org/timestampplugin.html

Resources