Refresh property every hour in Camel - apache-camel

Using this code
<propertyPlaceholder id="properties" location="file:${basedir}/etc/foo.properties"/>
Camel load foo.properties at application start: is there a way to reload foo.properties every hour?
It can be useful if foo.properties changes.

The camel-properties component has a property that can be used to control if properties have to be cached or not, see: https://github.com/apache/camel/blob/master/camel-core/src/main/docs/properties-component.adoc

Related

How to access header and property from callee in ASynch Route in Apache Camel

I have Apache Camel Route which listens to ActiveMQ queue. During the processing, at one point, route sets the header and property on the exchange.
Now during the integration testing, we want to check the value of the header and property.
The question is, how do we access these two things ie. header and property.
I have tried using the producerTemplate's asyncRequestBody/asyncRequestBodyAndHeader etc. With Future object I can access Exchange, however, I am not able to access the header and property set on the exchange.
I have made sure that the route is InOut type.
If you can get the exchange, can you not just use exchange.getProperty(name) to get the property you're looking for?
I have set properties in my route:
<setProperty propertyName="sampleProperty">
<simple>${body}</simple>
</setProperty>
and retrieve them later using {property.sampleProperty}

Dynamic Config Loading in Camel Application Bundle in Karaf 3.0.5

I have a simple Camel Application bundle which is to be deployed in Karaf 3.0.5 under Apache Service Mix 6.1. The configuration file is placed in etc/ directory (let's say it is named as wf.cfg). I want to have the dynamic config change functionality in my application bundle. So that whenever something is changed in wf.cfg it is immediately available to bundle. For this I have added the following in my
blueprint.xml
<cm:property-placeholder persistent-id="wf"
update-strategy="reload">
<cm:default-properties>
<cm:property name="env" value="local" />
</cm:default-properties>
</cm:property-placeholder>
<!-- a bean that uses a blueprint property placeholder -->
<bean id="configBean" class="com.jabong.orchestratorservice.basecomponent.config.ConfigBean">
<property name="env" value="${env}" />
</bean>
The problem I am facing now is if the update-strategy is set to reload. Then it seems to be reloading the entire bean.
Can someone let me know is there a way I can reload only the configBean not the entire bundle? If I can achieve this then may be I can have some static reference to the config variables inside the configBean which my application bundle can then make use of?
The full blueprint.xml is placed here.
the property-placeholder can have two values for the update-strategy :
reload: The blueprint container is reloaded asynchronously when the properties change. Any property change stops the context (and shutdown camel), and restarts it with the new property. everything is done automatically.
none: Nothing is done. The context is not shutdown (and so camel), but the properties are not injected. The property change are lost
There is another way to inject properties in Aries-Blueprint, through managed-properties : They decorate a bean definition, and dynamically inject the new property into the bean when the configuration change. There are here two modes : bean-managed (invoke a method when the configuration change) and container-managed (invoke a setter when a property change).
With this managed-properties you can dynamically intercept change in the configuration, and respond to it, without restarting the blueprint context (and consequently without stopping the camel context).
However, components in camel are not so dynamics : They read the configuration when an endpoint is created, but that's all. If you want to change the configuration of the route dynamically, it's not easy or impossible. You will have to stop/start the route.

Transacted camel route with auto-startup set to false

I am in the process of developing a message router which has a bunch of routes that are started and stopped at runtime based some certain conditions.
By default all these routes are configured with auto-starup=false
Now I am trying to add transactional support to these routes and it seems that you cannot define a transacted route and control the its startup behavior at the same time. This is because RouteDefinition.transacted() returns a TransactedDefinition instance which does not have an autoStartup(boolean autoStartup) method.
I am sure I am not the only one to need this kind of functionality and just wondering what is the camel way of addressing such requirements.
Thank you in advance for your inputs
Maybe just set autoStartup first, eg
from("direct:start").autoStartup(false)
.transacted()
.to("mock:result");

Apache Camel - Dynamically changing throttle values

Can anyone please give a sample on how to dynamically change the maxRequestsPerPeriod by using a Throttler processor instance or using a throttle element in Apache Camel ? (Reference - How to change Processor properties during runtime using Camel?)
We cannot use Expression with header because if the header is absent then the Throttler uses the old value. What we need is, in a bean based on some condition we have to update the throttle value so that it will be used until next update. In our case, we cannot use message header for this purpose.
How can we navigate the runtime processors in the route and find the Throttler to change it dynamically? Please help with a sample.
Thanks.
Thanks Claus..We will check jmx mbeans in upcoming Camel 2.16 release.
Now the following solution worked for us with Camel 2.15.2 :
Java DSL:
from("direct:start")
.routeId("throttleroute")
.throttle(ExpressionBuilder.beanExpression("throttleBean","getThrottle"))
.timePeriodMillis(2000)
.to("jms:test.MyQueue")
.beanRef("throttleBean", "receiveData");
Spring DSL:
<route id="throttleroute">
<from uri="direct:start" />
<throttle timePeriodMillis="2000">
<method ref="throttleBean" method="getThrottle" />
<to uri="jms:test.MyQueue" />
</throttle>
<to uri="bean:throttleBean?method=receiveData" />
</route>
Here throttleBean.getThrottle() method will be having the logic to generate and return the required throttle value dynamically.
You can change it using JMX eg the management api.
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/api/management/mbean/ManagedThrottlerMBean.html
The mbean has JMX attributes to change the values at runtime.
In the upcoming Camel 2.16 release you can easier get hold of the jmx mbeans from java code using
https://github.com/apache/camel/blob/master/camel-core/src/main/java/org/apache/camel/CamelContext.java#L545
Just that you know the id of the mbean. You can assign ids in the routes, so its using a known id, instead of auto generated. Which btw also makes it easier to find the mbean using pure JMX api.

Visualforce Page navigation issue

I have pretty long Visual force page in my application i have to requirement to save it automatically for every 60 sec seconds.So whenever i save the page the cursor goes to the top of the page instead of being where they are previously present.Can anyone give me answer on how to handle this issue?
Use JavaScript Remoting instead of a apex:actionPoller. JavaScript Remoting doesn't invoke a page refresh automatically. So set up your timer in JavaScript using setInterval() and when it fires your JavaScript method, call the Apex save method that does the saving you want from there.

Resources