I am using camel 2.9.0 in my project. We have a number of routes divided into different camel contexts. Each camel context is bundled separately and deployed in Apache Karaf. Now the problem is divied into 2 parts:
1.) Each route is a scheduled route. Although using Quartz component, we are able to define a cron expressio in each route, we want a console where in we can trigger,stop any route and also put a cron expression to any route.(Scheduling a route through a web console is our main objective).
2.) Also we tried to configure the cron expression for each route through quartz.property. But if someone wants to change the cron expression at runtime in Apache Karaf, then we have to stop the bundle deployed and start in again. What can be done to change the value of cron expression at runtime.
Any replies and help would be appreciable.
Piyush
JMX provides remote context/route management support (start, stop, etc)
see these posts for more information:
http://www.consulting-notes.com/2010/08/managing-camel-routes-with-jmx-apis.html
http://www.consulting-notes.com/2011/01/apache-camel-monitoring.html
otherwise, to add/remove/alter routes at runtime, you'd need to get a handle to the CamelContext and leverage its APIs (addRoute(), removeRoute(), etc)
see these for more information:
Add camel route at runtime in Java
http://camel.apache.org/loading-routes-from-xml-files.html
Related
I am looking for a way to store system processes / tasks that the application will then execute according to the specified system-wide conditions. The point is that the system should check the input variables and trigger specific actions in the system according to the rules of the process.
I am probably looking for some form of meta-language that I can write rules / actions and that can be programmed to start and stop based on input system parameters.
In what format record such processes?
How to parse these jobs?
What design patterns apply to this?
Are there any existing solutions on this use-case?
Which Java libraries to use for this.
If anything is unclear, I will gladly complete the question.
Thank you.
You could try Spring Batch. It introduces it's own domain language for jobs and allows configure them both using XML or java.
Here are couple of examples from their reference guide.
XML config:
<job id="footballJob">
<step id="playerload" next="gameLoad"/>
<step id="gameLoad" next="playerSummarization"/>
<step id="playerSummarization"/>
</job>
Java config:
#Bean
public Job footballJob() {
return this.jobBuilderFactory.get("footballJob")
.start(playerLoad())
.next(gameLoad())
.next(playerSummarization())
.end()
.build();
}
Spring Batch provides functionality for repeating or retrying failed job steps as well as for parallel steps execution.
For some tasks also Apache Camel can be used. It although provides its own DSL and both XML and Java configuration options.
Both frameworks provide abstractions for description of sequence of actions, which should be done during the job. Apache Camel is more convenient for jobs which require some integration tasks (sending messages in JMS queues, calling REST- or Web- services, sending emails etc). Advantage of Spring Batch is ability to configure application behavior in case of an error or temporary inaccessibility of a service, which should be called (repeat / retry mechanisms). Both frameworks can be integrated with each other: you can call Spring Batch jobs from Apache Camel routes or initiate Apache Camel routes from Spring Batch jobs.
Most complicated solution would be usage of some BPMN engine (e.g. Camunda, Apache Activiti, jBPMN), but that probably would be an overkill.
do not judge this question) I want to implement WEB installer for my Spring Boot application, and very interesting moment is that my application plays 2 role: Installer and Backend(Application). When i first run my app i need to tell Spring to not initialize particular beans(Hibernate(while startup application must not to be failed to start because database may not exist), ActiveMq and others beans that will be added in installation process) and show some html pages with installation guide. Also i need to prevent access to endpoints where some logic with database occurs. When installation finished i will create new application.properties or some other file with settings and i tell Spring to initialize all required beans with Hibernate, ActiveMQ and others. Maybe i will make restart of application and new behaviour that based on installation will occur. And in next starts my application will not show installation guide. To simplify the question: I need to change startup behaviour of Spring Boot Application. For fun i can give an example with human: I need to make human live with no organs, and this human will live very good, and if i want i can add organs to human and he will be live very well))
You can use #Profile annotation. Check this link: https://www.mkyong.com/spring/spring-profiles-example/
I have an existing java application that uses spring and hibernate and is deployed in AWS EBS environment. I now have a need to support thousands of light weight but persistent jobs and am considering using quartz for managing those jobs.
First, does anybody who has done this before see any issues or has word of wisdom. Second, I am looking for samples of managing a separate bean in this application that would start the scheduler so that it could run jobs, add more jobs or delete jobs that are not needed anymore. All the samples that I have seen so far use xml configuration. My environment does not have any xml configuration. Are there any samples that I can use to accomplish this in a configuration-less spring environment.
Thanks for your help in advance.
Waqar
I think Camel can help you
http://camel.apache.org/quartz.html
http://camel.apache.org/cronscheduledroutepolicy.html
CronScheduledRoutePolicy startPolicy = new CronScheduledRoutePolicy();
startPolicy.setRouteStartTime("*/3 * * * * ?");
from("direct:start")
.routeId("testRoute").routePolicy(startPolicy).noAutoStartup()
.to("mock:success");
we are using camel direct component in our project.
Application will work fine most of the time.
But sometimes services won't work because of following exception.
if we restart server again things will go normal.
we are not following any route startup order to start camel routes. All routes will load at deployment time only.
we are using camel 2.16.1 version.
Could any one suggest what causing this issue and why it is occurring often.
Caused by: org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: Endpoint[direct://framework-logger-service].
This error occurs when "direct://framework-logger-service" route is not initialized in your application context.
but if it occurs sometimes then direct being a synchronous component it may not be available for accepting requests while processing other requests.
This behavior is possible when you send huge number of requests to direct component.
The simple approach will be split your direct to two components to load balance
from(somesource).to(direct:total);
from(direct:total)
.multicast()
.parallelProcessing()
.to(direct:part1,direct:part2);
Im developping non OSGI app and i need to update the values of some properties used in camel routes (loaded BridgePropertyPlaceHolder).
So I thought:
To use Hawtio, the cool mangement console, in order update camel using JMX
Create a JMX MBean that will update the properties ..
I successfully create the MBean operations and call them using JMX, but I can't figure out how to update the camel routes that depends on these properties.
Is there a way to update the camel context externally?
Update:
Exemple of use case:when a remote server doesn't return response, we keep sending messages until we reach the max of unsuccessful attempt(messages without ack).
in camel we create a router pattern based on property loaded from file system.
This property can change occasionally, and we want to do this without restarting server, but the problem is that camel parse routes when starting context and i can't find no mean to update routes accordingly.
I am grateful for any proposal that could help:)
If you use Camel error handling to retry (redeliver) then you can use the retryWhile to keep retrying until you return false. This allows you to use java code etc, and that allows you to read the updated configuration option.
See more details at
http://camel.apache.org/exception-clause.html
And if you have a copy of Camel in Action book, see page 152
For what properties you want them to be dynamic.you can move those prop to some db and fetch them whenever you are reading.I think a redesign is required for your camel route.
Changing from endpoint parameters such as URLs etc., following procedure has to be used according to dynamic change endpoint camel:
stop the route
remove the route
change the endpoint
add the route
start the route
If the to endpoint has to be configurable, you may use the recipient list component. Here you may read properties from a database and/or from the filesystem using the appropriate Camel component.