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.
Related
I have multiple routes deployed in a single camel bundle and what I'm trying to achieve is that once a single route starts execution, the other routes should not be executed until the route that got started is finished with execution.
I understand that it is possible to have the whole camelContext encompassing my routes be made single threaded but I see a drawback here in terms of performance.
Has someone had a similar use case and whats the best way to solve this? Since I'm using OSGi Blueprint DSL, any examples will be welcome.
You can use Camel's Control Bus if you need to control other routes selectively, such as starting and stopping them.
First, you need to prevent the routes you want from executing when your application is started. This is achieved with autoStartup=false in your route definition:
<route id="foo" autoStartup="false">
<from uri="activemq:queue:special"/>
<to uri="file://backup"/>
</route>
Then at the point in your running route where you want to start another route after doing stuff, simply:
<to uri="controlbus:route?routeId=foo&action=start"/>
You can also order the startup (and shutdown) of routes, explained in the Camel documentation here.
I'm working on a logging solution where Camel routes are defined at runtime with a Java DSL String. I wonder if there's a way to check programmatically some errors such as components not found in the route. The only option I was able to find is catching the org.apache.camel.ResolveEndpointFailedException and dig into the error message. Is there a better way to validate the route?
Just to give an example, it would be good to ascertain if a route syntax is completely wrong or if just a component wasn't found so that I can output a message e.g. "install ftp component".
You can use Fabric8 Camel Maven Plugin (http://fabric8.io/guide/camelMavenPlugin.html) for validating Camel endpoints in the source code.
Look at this article by Claus Ibsen to get more information : https://blog.fabric8.io/cheers-fabric8-camel-maven-plugin-to-validate-camel-endpoints-from-source-code-8768aff76b41#.wcji8hfdg
I have the following in a camel route, but it doesn't seem to get the header value. Is this the right way to do it?
<to uri="ahc:http://${header.freeNasServerIp}:80/api/v1.0/storage/volume/"/>
See this FAQ about dynamic to:
http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html
See this link How can I invoke a RESTful service through Apache Camel?
Answer specific to this question is:
<recipientList>
<simple>ahc:http://${header.freeNasServerIp}:80/api/v1.0/storage/volume/</simple>
</recipientList>
can't find anything on this online, anyone know how to do the equivalent in blueprint as per the following spring-camel beans setup :-
<!-- define our filter as a plain spring bean -->
<bean id="csvAntFilter" class="org.apache.camel.component.file.AntPathMatcherGenericFileFilter">
<property name="includes" value="*.csv"/>
</bean>
<route>
<from uri="file://inbox?filter=#csvAntFilter"/>
<to uri="bean:processInbox"/>
</route>
My understanding (sorry still fairly limited with camel), is that AntPathMatcher is part of camel-spring and not camel-blueprint so can't use it this way if i want to use blueprint.
Or is there a better way to do this in blueprint ?
Edit
I've found that there exists camel-core-xml but unsure on how to utilise the AntPathMatcher within it.
The Ant path matcher is part of camel-core, so you can use it with blueprint also. It used to be part of camel-spring but we moved it into the core, so people can use it without Spring, eg just Java or Blueprint etc.
Though it depends on which Camel version you use, if its in camel-core etc.
I am currently building upon the camel-drools example found here: https://github.com/FuseByExample/camel-drools-example
The route is as follows:
<route trace="false" id="testRoute">
<description>Example route that will regularly create a Person with a random age and verify their age</description>
<from uri="timer:testRoute"/>
<bean method="createTestPerson" ref="personHelper"/>
<to uri="drools:node1/ksession1?action=insertBody" id="AgeVerification">
<description>valid 'action' values are:
'execute' that takes a 'Command' object (default)
'insertBody' that inserts the Exchange.in.body, and executes rules
'insertMessage' that inserts the Exchange.in (type org.apache.camel.Message), and executes rules
'insertExchange' that inserts the Exchange (type org.apache.camel.Exchange), and executes rules
</description>
</to>
<choice>
<when id="CanDrink">
<simple>${body.canDrink}</simple>
<log logName="Bar" message="Person ${body.name} can go to the bar"/>
</when>
<otherwise>
<log logName="Home" message="Person ${body.name} is staying home"/>
</otherwise>
</choice>
</route>
I have expanded on this example for my own project and have added more complicated rules and different Facts, which I would now like to debug, however I can't figure out how to get Drools debugging working in the camel / fuse environment.
I would ideally like to see all the various debugging views that the Drools IDE provides such as the agenda view, working memory view, etc (as per http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html/ch06.html#d0e8478). I have converted my Eclipse project to a Drools project. I have created a new 'Drools application' debug configuration, but have no idea what to put in the 'main class' section. I don't have my own main class since it's camel that invokes the firing of the rules and inserting facts into the working memory.
I've tried debugging the application as a normal Java application, so I set breakpoints before the drools part of the application is executed. I have followed the drools documentation that says that if you set normal breakpoints and click on the workingMemory variable that the drools 'Working memory' or 'Agenda' view should then populate, however I always see 'The selected working memory is empty', even though I know that it isn't. I've stepped through the code from start to finish clicking on all possible WorkingMemory variables but i still see 'the selected working memory is empty' error.
Has anyone been able to successfully debug drools when deployed using camel? If so, what steps did you take?
Cheers.
I use the KnowledgeRuntimeLogger to help debug my camel/drools app. It creates a log file that I view in the Audit view (you can drag it into the view in eclipse).
KnowledgeRuntimeLogger flogger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession,"c:/temp/wmlog");
If you need to do this in spring, you can create it as a bean with the two constructor arguments (or create you own little bean that creates the logger).
hth