Number of routes in a camel bundle - apache-camel

We have a lot of routes in a camel bundle. And we want to add few more.
Do we have a limit on the number routes we can have in a bundle?
Is there a performance bottleneck directly proportional to the the number of routes we have in a bundle?

As Claus mentioned, there is no limit to the number of routes
I would add to Claus's performance answer that the number of threads starts to become an issue when you get to the 100's-1000's of routes.
To optimize at that scale, leverage shared logic in routes where possible (direct, direct-vm, seda, vm:// endpoints).
Also, many routes that start with a http-listener can be consolidated to a single route that listens to all endpoints, then does a CBR/dynamic router to various sub-route handlers. This helps cut down significantly on the number of threads and thread pools running around that get started by listener Camel components.
Similar approach applies for other transport technologies.

Related

Sharing state in 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)

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.

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

Start Camel route in suspended state

Is there a way to build Camel routes that starts in suspended mode?
I'm looking so to say "declutch" at start up, then at some stage quickly start processing messages by just calling resumeRoute(routeId)
I could perhaps just create the route and then quickly call suspendRoute(routeId), after the route has been created, but at that stage, it would probably have consumed some messages (for instance in the case of JMS routes or polling consumer routes).
generally, you'd just disable the route by using autostartup(false)...
I assume you are asking though because you need the route started (warmed), but not active. In that case, then you should be able to use a custom route policy and some external variable to get this behavior

Where is the best place to do routing in google appengine?

In google app engine, you can do routing at 2 places: in your app.yaml, you can send requests to url's off to different scripts, and inside a script, when you work with wsgiApp, you can again do routing, and send different url's off to different handlers. Is there an advantage of doing your routing in either of these places?
Generally the best approach is to use app.yaml for 'application level' routing - defining paths for static content, utilities like mapreduce, and your main application - and doing the routing for your app from within a single request handler. This avoids the overhead of defining multiple request handlers for each part of your app, while still preserving isolation for distinct components such as external utilities.
You have to use both. Do the high level routing in app.yaml and the more fine grained routing in the wsgi. The important is that you get a god structure of what is routed in each place. I can not see any argument that the one is superior to the other.

Resources