How to deploy Custom Dataformat in camel - apache-camel

I am running Camel inside Karaf.
I have created a custom dataformat by implementing DataFormat interface.
Now I have my custom class.
In order to make it visible to my camel route inside karaf where to copy this class file?
Please provide guidance.

I'd just add it to my Camel application source code and deploy it with that bundle. If you need to reuse it across several bundles, then you could package it as a separate bundle and export/import it appropriately I suppose...

Related

Camel K with Jolt transformer

I am using camel and use JOLT transformer to transform from JSON TO JSON and it works fine when deploying on spring boot or even when using camel as stand-alone. But when trying to switch to Camel-K I am facing some problems, I cant refer to the Jolt template transformation inside the camel route or even add it to the deployment. Anybody have the info on how can I attach the Jolt transformer template to camel K to be able to use it in the route.
Thanks.
you can use the --resource flag to add a resource to the camel-k classpath:
kamel run my-integration.groovy --resource=spec.json
and then use in in your integration
to('jolt:spec.json')
we are working on improving the support for resource handling: https://github.com/apache/camel-k/issues/2003

Camel 2.21.1 RouterBuilder OSGI Service getting exception due to Simple language not found in OSGI Service Registry

I am extending Camel RouteBuilder in order to define a Camel route, thus my specialized class is a OSGI component and on #Activate method the camel context is being created, like:
camelContext = new OsgiDefaultCamelContext(bundleContext);
After that the camelContext.addRoute(this) method is invoked, but when the camelContext.start() method is invoked the org.apache.camel.NoSuchLanguageException is threw. Thus, looks like there is a racing condition due to org.apache.camel.language.simple.SimpleLanguage is not register yet in OSGI SR.
Note:
There is no OSGI injection in route builder specialization, thus this one will be ready to activate sooner even before camel-core components.
Then, I'm wondering if it's a issue once makes no sense to my custom bundle add Camel internal dependency (like to SimpleLanguage reference) just to get out this racing condition.
You need to do more setup of CamelContext if you manually create Camel in OSGi.
if you crate osgi camel context yourself, there is a few more setup you need to do
take a look in camel-core-osgi there is a helper class with a method that setup a bunch of stuff
I'm wondering if there is a race condition with Camel-core activator and my custom bundle (no Camel OSGI dependency at all), because bundle language is register with the following invoke stack bundle activation

Is there a KairosDB component for Apache Camel?

I can't find a Camel component for KairosDB. Is there none?
Should I write a custom component or is there a smarter way?
Thanks
There is no official component for that. You can find the list of components at: https://github.com/apache/camel/tree/master/components#components
Yes you would need to write your own component, or just use regular Java code in a Java bean to integrate with KairosDB and then Camel can integrate with your Java bean. Or use a Camel Processor instead of a Java bean.
But writing a component is not so hard, and if you use KairosDB in more projects with Camel then it starts to make sense to build a Camel component for it. The Apache Camel project loves contributions: http://camel.apache.org/contributing

Apache camel route deployment - Independently?

Suppose I have 10 different Camel routes in my application, is it possible to stop one particular route alone during an issue and make changes to it(in one of the java processors) and deploy it again without affecting other routes.
Also can I create and deploy a new route on the fly, while other routes are already functioning.
If these are not the default behaviour, what are the options available to achieve this?
Karaf (so do Apache ServiceMix / JBoss Fuse)has hot deployment (nowadays this might be supported in JBoss AS / WildFly as well ). Meaning, you can create your routes as independent blueprint xml files in the deploy folder (meaning just xmls). Likewise you can have xml files for every route, whenever you make changes to XML's, it will be redeployed automatically.
This approach has few drawbacks, it will be complex if you have to deal with JPA or if your route has to deal with custom processors / classes.
Check out the examples in Apache ServiceMix / JBoss Fuse project.
I would recommend this approach especially if you want to take a microcontainer approach - Something like light weight Apache Karaf + Camel Route XML files + Docker.
I have done this few years back, may be this feature is possible to achieve in any other containers as well, which I am not sure.
You can stop a route via org.apache.camel.CamelContext.stopRoute(id) & you can modify it by building a new route and adding it to the context. This would let you change the logic of a route at runtime.
This wouldn't automatically let you hot deploy a new Java processor. I think this aspect of your question isn't Camel specific - their seem to be a few options for this, including OSGi/Karaf mentioned by #gnanaguru.
Perhaps moving the logic that you think might change from a Java processor to somewhere more dynamic (like some JavaScript in an external file, or in the route itself) would be a simpler solution to your problem.

Custom Tomcat Valve contained in web app WAR file

I'm looking to implement a custom Valve and configuring it using META-INF/context.xml.
At the moment though, when context.xml is parsed during deployment, Tomcat (6.0.32) dies with a ClassNotFoundException on my custom Valve implementation.
I'm under the impression that I'm running into a class loading context issue and I'm not 100% sure I understand it.
Is my class not found because it is located in the WEB-INF/classes file and the Context level class loader is unable to locate the class because of the hierarchy?
Thanks in advance.
You can not load Valves from inside the webapp class loader. If you look at http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html it shows the available class loaders. You must use one of the Bootstrap, System or Common classloaders because Valve definitions are processed BEFORE the individual webapp classloaders are created: the Context has to be processed before the webapp is available.
Package your Valve in a jar by itself and copy it into the $CATALINA_HOME/lib folder and you should be all set.

Resources