Is there a AntPath matcher equivalent in Camel Blueprint - apache-camel

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.

Related

Synchronizing camel route(s)

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.

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.

How to use a header value inside an XML attribute using Apache Camel?

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>

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.

Debugging drools when deployed in camel / fuseesb

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

Resources