Sharing state in camel? - apache-camel

It appears I am running into issues sharing information between routes.
What is the camel pattern for passing around information ?
I looked at exchange properties but that does not stick around between routes I think...
eg:
one file has one has some configutations
i have a route to read this file
and several other routes that will act on based on the configs,
how do I accomplish this ?
I thought of puttin the values in a singleton bean, but that seems kind of ugly...

Exchange properties are preserved across routes inside camel (but there are some limitations and special cases when using splitter/aggregator etc.)

Assign ID's to all sub routes which will act on based on the config. Then get the suitable Route or RouteDefinition from camel context and check whether you can advice or share information to the route according.
ModelCamelContext modelContext;
modelContext.getRouteDefinition(String routeId) or modelContext.getRoute(String routeId)

Related

Apache camel Endpoint schemes duplication

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());

Apache Camel unique property name in two different routes

We have multiple routes running independently on a quartz scheduler, most of the functionalities are similar, so we have created some common routes to call inside parent routes for code reuse.
Is generic route property will be treated as a local variable and will not be shared among two different routes or value of the property will be changed by some other route.
<setProperty propertyName="remoteServerException">
<simple>${exception.message}</simple>
</setProperty>
Above is one of the property used in common route, and called from multiple routes, is it fine to be called like this? Please advice.
The <setProperty> is referring to properties on the Camel Exchange which is the instance, that contains the message being routed - there is one Exchange per message and its not shared - its local for that given message. So if you have some kind of shared route, you call via direct endpoints etc, then calling <setProperty> will not cause harm, its operating only on the Exchange instance.

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");

how to share data between different camel contexts

Is there a way to share data through different contexts.
I have created a custom component which i want to initialise only once.while initialising iam setting some properties which iam not able to access in another context.
How to access those?
Thanks.
Regards
Senthil Kumar Sekar
I believe you are looking for the VM component. This component provides an asynchronous way of sending messages across camel contexts with a SEDA-fashion. For more info, please refer to the actual documentation.
Also, I am not sure how you are setting those values but you could use two routes within the same context probably. Have you tried that?

Disable Dynamic Routing capability in Camel

With Camel, it is possible to add routes dynamically to the context. And it appears the context is always passed as part of the exchange.
Is there a way to prevent applications from adding routes at runtime? I looked at Shiro security but did not seem to find something along those lines.
the only thing I can think of is to wrap interactions with these applications using POJO Bean Binding which only passes the body of the Exhchange around and limits access to the Exchange directly...
see http://camel.apache.org/bean-binding.html
Maybe you can extend DefaultContext and add security rule in that.

Resources