I have a route that uses aggregation strategy, because of that it produces a AggregateDefinition as opposed to RouteDefinition. The CamelContext provides API to add a RouteDefinition but not an AggregateDefinition.
How can I add an AggregateDefinition to the camel context dynamically at runtime ?
Thanks
Srikanth.
You can load/update routes from xml files as shown here:
http://camel.apache.org/loading-routes-from-xml-files.html
Otherwise CamelContext has Java API to add/remove/update routes as well. For example you can use a RouteBuilder class and just add that to the camel context using the api.
Related
in apache camel, we have endpoints associated with scheme strings like "cxf", "ahc", "http" and the likes. What happens if there are two components built using the same scheme? I don't see a validation from camel framework which prevents the deployment of components with duplicate schemes. Should there be a validation in the first place or this is by design?
Regards
Gopal
I have a need to re-use available camel components from the community but change the endpoint scheme to make it unique. For example I want to use amqp component but in my blueprint route i would like to have unique scheme used "<camel from uri="mydomain-amqp">. This way I can re-use the amqp as a new component but also keep others using the amqp as is.
Camel prevents adding a component using a name/scheme that already exists. Adding your component under a different name would be something like this:
getContext().addComponent("mydomain-amqp", new AMQPComponent());
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
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
Suppose I have a Jetty component comp1 and custom component comp2, where comp1 produces an exchange and comp2 consumes it.
How do I get the exchange of Jetty component in consumer of comp2.
So far I have observed that we can obtain it in consumer's poll() method as -
SomeEndpoint endpoint = camelContext.getEndpoint("someURI", SomeEndpoint.class);
but what to configure at someURI and someEndpoint.class ?
if I mention someURI = "jetty:..", then my consumer will not consume message from anyother endpoint, so how to configure it for generic ?
You must first create skelatal code for your custom component using
mvn archetype:generate -DarchetypeGroupId=org.apache.camel.archetypes -DarchetypeArtifactId=camel-archetype-component
-DarchetypeVersion=2.14.1 -DarchetypeRepository=https://repository.apache.org/content/groups/snapshots-group
-DgroupId=org.apache.camel.component -DartifactId={YourArtifactId}
your component Prefix file is located in this location
src/main/resources/META-INF/services/org/apache/camel/component/
The name of this file is your component prefix. You provide this name when you generate the project from the first step.
Lets say its name is comp2. Now you simply need to configure your routes in this manner:
from("jetty:abc").to("comp2:xyz");
Your component's jar must be provided as dependency to the application that configures the Camel Route.
You need to implement the Component Class, Endpoint class, Consumer and Producer class in case required.
Spring DSL allow you to do something like this:
in between consumer and producer you can add you custom producer
<route>
<from uri="component1 uri"/>
your other process code
<to uri="component2 uri">
</route>
I tried to annotate a RouteBuilder with #ManagedResource and a method from it with #ManagedOperation but i can't find it in JConsole. The other classes including my annotated custom endpoint is showing up fine.
I am not sure if these annotations work with all kinds of classes within camel?! In my case the annotated RouteBuilder is some kind of central control class. Is does not contain a route but is loading several other RouteBuilders. It also adds global (context scope) exception handlers and adds a RoutePolicyFactory that centrally handles start up and control logic.
The methods i want to make available via JMX re method that start/stop certain groups of routes.
for sake of completeness i add the answer i got an camel mailing list:
You have to simple implement Service or StaticService (for Singleton Services) and add it to CamelContext via addService.