Adhoc execution of Apache Camel route - apache-camel

I have a couple of Apache Camel routes created using the Java DSL and Spring.
#Bean
public CamelContext camelContext() throws Exception {
CamelContext camelContext = new DefaultCamelContext();
camelContext.addRoutes(route1bean());
...
camelContext.start();
return camelContext;
}
These routes use quartz2 component for scheduling and everything works as expected.
The jobs can however have errors when running and there is a requirement to retry them manually. I'm looking for a way to make adhoc manual execution of the route using hawtio or in Java code.

Yes , use jconsole. There are many mbeans exposed by camel. You can use them to start and stop. Of course you can do the same using Hawtio as well.
Updated based on your comment:
I get what you mean, This is the approach I will take. Create 3 routes. 2 light weight routes - Route A with Simple File From endpoint, Route B with Cron and Route C with direct:bla From endpoint, which contains the actual business logic. This way, you can trigger Route A whenever you want, Route C is common, Irrespective of when Route B is triggered by the cron.

Related

Apache camel - How to retrieve Endpoint URIs for a given Component

I use Apache Camel 2.20x.
A camel component can be developed with a uri scheme for example "sample-component". Now the Endpoint of this component can actually extend an existing Endpoint say SQL which has uri syntax as "sql:<select query">.
Now I am listening to camel Exchange event (ExchangeSentEvent) When I retrive the uri from the event I get "sql:<select query">. But what I want is to get "sample-component". How can we achieve that. In simple terms following is the ask
How can we get all Endpoint uri schemes for a camel component.
Thanks in advance
Gk
ComponentName+Endpoint . You can see all the uri that the component will take. All camel components are named this way.There may be exceptions. also if u use intellij idea apache camel plugin it show .
examples
HttpEndpoint
TimerEndpoint
SedaEndpoint
DirectEndpoint
You can also find the consumer and producer classes of these components as follows.
HtppProducer if support HttpConsumer ..

Reusing Apache Camel route and avoiding sleeping the thread

I am working on a project where I am using Apache Camel to establish a connection to a URL using Java code in a method:
public void establishConnection()
{
final CamelContext context = new DefaultCamelContext();
camelContext.addRoutes(new RouteBuilder(){//logic});
camelContext.start();
Thread.sleep(7500);
camelContext.stop();
}
The issue is that it is necessary to pause the thread, otherwise the following code executes, so to wait for the response as it takes camel time to start.
Now the issue is if this method gets called many times and I want the camel context to be initialized once only with the route so that we dont have to use the sleep here for subsequent calls.
What context are you in? You don't need to do the work to start/stop by yourself (as Adam also commented), Camel does it for you.
When you are building a Spring Boot application, check out how to use Camel with Spring Boot.
When you use Camel standalone, have a look at this example.

Difference between CamelContext and Registry in Camel

I'm new to Camel and bit confused between CamelContext and Registry.
As far as I know that CamelContext is the base object like ApplicationContext in Spring that is used for add routes and maintains the camel life cycle.
Also we got the Registry object from CamelContext but not sure what is the main purpose of this registry.
My intention is to add the component in the context/registry so that JNDIBind can look up the components.
CamelContext: Kind of Camel Runtime that keeps everything in Camel together, e.g.: Endpoints, TypeConverter, Routes, Components and Registry(!).
Registry: allows you to lookup beans, which by default will be JNDI beans. If you use the spring integration it will be Spring's ApplicationContext.
Generally camel when used with spring makes use of the ApplicationContextRegistry to lookup components, endpoints etc with the name of the bean defined in spring-bean.xml file. In places where we need to use JNDIRegistry we would have to add that registry when creating the CamelContext. This is used in places where JNDI objects are shared accross multiple JVMs where JNDI is the best solution.
Please see different types of registry implementation for camel: camel registries

camel: error handling during route startup

Looking for some help handling the error conditions that may occur during camel route(s) startup in a context. We are using java dsl to create routes after reading a configuration. when one of the configuration is wrong (e.g. missing host name in sftp uri. runtime discovery of error in this case), all subsequent routes are not even started by camel. What we are trying to achieve is, log an error for faulty case and proceed with subsequent route.
Is there any interceptor for same?
I would need more information to provide you with a more exact answer; however, it looks like you should be able to use the onException clause as part of RouteBuilder configuration. Here is an excerpt from the JBoss Camel guide:
Scopes
The onException clauses can be effective in either of the following scopes:
RouteBuilder scope—onException clauses defined as standalone statements inside a RouteBuilder.configure() method affect all of the routes defined in that RouteBuilder instance. On the other hand, these onException clauses have no effect whatsoever on routes defined inside any other RouteBuilder instance. The onException clauses must appear before the route definitions.
All of the examples up to this point are defined using the RouteBuilder scope.
Route scope—onException clauses can also be embedded directly within a route. These onException clauses affect only the route in which they are defined.
https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.1/html-single/Apache_Camel_Development_Guide/#BasicPrinciples-ExceptionHandling

Reconfiguring Apache Camel route parameters at runtime

I have aggregation configured in my code:
.aggregate(new BodyAggregationStrategy())
.constant(true)
.completionSize(1000) // Static value
.completionTimeout(300) // Static value
After I have started the Apache Camel context is it possible to change various parameters like completionSize and completionTimeout values?
When context is running a lot of data are transfering throught it and I want to increase some parameters like queue size and so on.
What you could do, is via the CameContext
stop the route
remove the route
add the route with new parameters
start the route
Have you tried to connect via JMX and see if those parameters can be configured?

Resources