Camel Route for Javamail Not Stopping on Shutdown - apache-camel

I've a simple route
from(
"myQuartz://EMAIL_Route?cron=0+0/5+*+*+*+?")
.routeId("EMAIL_Route")
.shutdownRunningTask(
ShutdownRunningTask.CompleteCurrentTaskOnly)
.beanRef("errorReportProcessor")
.filter((body().isNotNull()))
.to("smtp://smtpHost?From=someone&to=someoneElse&Subject=something").end();
Even if I shutdown the application in Websphere application server, I still continue to get emails. The scheduler/thread is not stopping. In my quartz properties file, I also tried
org.quartz.scheduler.makeSchedulerThreadDaemon=true
but, fruitless. The Camel, Quartz and Mail component version is 2.12.4. Spring 3.2.5.Release. Websphere 8.
SystemOut.log files clearly mentions, the application stopped without errors. However, I can see a java.exe instance running in task-manager.

OK. I found the issue was with missing "root-app-context". Once, I configured the "root-app-context", the Cron-scheduler is now stopping and no more stranded threads. :)
Even the extra configuration to makeSchedulerThreadDaemon was not required.
org.quartz.scheduler.makeSchedulerThreadDaemon=true

Related

Message duplication when starting not initialized route (noAutoStartup), then stoping and starting again

Is it legal in Apache Camel to start route (and consumer) after it was stopped programmatically?
I have route which is not started automatically (noAutoStartup()). App is also using Spring Boot.
Now, starting this route, stopping and starting again causing to consumers to be duplicated; observed on Hazelcast consumer.
I've tried to add ServiceHelper.startService(consumer) and ServiceHelper.stopService(consumer) with no effect.
I tried to stop route using camelContext.stopRoute(route.getId()) and control bus - same effect.
Camel 2.19.4; 2.20.1
Solution:
It turned out that HazelcastComponent cannot be stopped because it listens to events from Hazelcast and do not unregister this listener during component shutdown.
However, this component is deprecated since 2.20.x, and part of its functionality is available in HazelcastQueueComponent. Finally, HazelcastQueueConsumer in POLL mode respects the fact that service is stopped.

hystrix stream not responding

I am using spring-cloud-starter-hystrix:1.2.3.RELEASE in a Spring Boot application. I have 1 HystrixCommand, that I can execute successfully.
After that I called
localhost:8080/hystrix.stream
however this Request loads forever and doesn't respond. On Google I cannot find anything about this.
This happens if no command has been executed yet and therefor there are no metrics to publish in the stream.
The 'workaround' is to execute a Hystrix command.
This happens in Hystrix 1.5.8 and earlier. The behavior was changed in Hystrix 1.5.9 that was released yesterday. It will now publish a ping message if there are no metrics to publish.
This change was made to fix a bug where the stream would not detect closed connections when there were no metrics to publish. See Hystrix bug 1430 for more information.
Make sure you have the #EnableHystrixDashboard annotation added to the dashboard application. Then go to http://{dashboard-application:port}/hystrix.stream. On this page you will be asked to enter the URL of Hystrix application which is annotated with #EnableCircuitBreaker and of which you want to monitor the stream.

Monitoring if camel routes work as aspected

I'm looking for a best practise how to monitor the functionality of camel routes.
I know there are monitoring tools like hawtio and camelwatch, but that's not exactly what I'm looking for.
I want to know if a route is "working" as aspected, for example you have a route which listens on a queue(from("jms...")). Maybe there are messages in the queue, but the listener is not able to dequeue them because of some db issues or something else(depends on the jms provider). With the monitoring tools mentioned above you just see inflight/failed/completed messages but you don't see if the listener is able to get the messages -> so the route is not "working".
I know there is also apache BAM, maybe I have to do some more research, but somehow it looks like BAM creates new routes and you can't monitor existing routes. I also don't want to implement/define such business cases for each route, I look for a more generic way. It's also mentioned on the camel 3.0 idea board that BAM wasn't touched for 5 years, so I think people don't use it that often(which means for me it doesn't fit their needs exactly).
I had similar requirement some time ago and at the end I developed a small Camel application for monitoring.
It run on timer, query different Camel applications installed in remote servers through JMX/Jolokia and if LastExchangeCompletedTimestamp of the route I am interested in is older than some time interval, send a mail to administrators.
Maybe this approach is too simple for your scenario, but could be an option.
(Edit: more details added)
Principal points:
Main routes queries DB for entities to control and spawns controlling routes
Controlling routes fires on quartz and http post the following url
.to("http://server:port/app/jolokia/?"+
"maxDepth=7&maxCollectionSize=500&ignoreErrors=true&canonicalNaming=false")
sending the following jsonRequest body
LinkedHashMap<String,Object> request=new LinkedHashMap<String,Object>();
request.put("type","read");
request.put("mbean","org.apache.camel:"+entity.getRouteId());
jsonRequest=mapper.writeValueAsString(request);
As response you get another JSON, parse it and get LastExchangeCompletedTimestamp value

Camel route does not log when deployed in ServiceMix

I referred below article and created dependencies and log4j properties
http://camel.apache.org/how-do-i-use-log4j.html
Here is my simple route
from("direct:start")
.routeId("LogEipInfoLevelRoute")
.log(LoggingLevel.INFO, "Displaying Something - ${body}")
.to("mock:result");
Once i deploy my route in servicemix, im checking service mix log. I couldnt find any such message logged. except the route creation message with specified id.
Am i checking it in the wrong place?
You need to send a message to the direct:start endpoint for anyting to happen.
If you just want to see something going on, then you can use a timer instead of direct, eg
from("timer:foo?period=5000")
to figure a new message every 5 seconds. Notice the message body is null from a timer.
I assume that you are using OSGI Based ServiceMix version
Please execute following command in karaf console:
karaf#root> log:display | grep Displaying
More about ServiceMix logging systems can be found under http://servicemix.apache.org/docs/4.4.x/users-guide/logging-system.html
You must pass something to direct:start for something to happen. You can read more here about using direct : http://camel.apache.org/direct.html
I would just suggest using a timer to kick off your route. Once your route is kicked off by the timer your log will be written out to your log file.

How do you debug CXF endpoint publishing?

Given the "cxf-osgi" example from fuse source's apache-servicemix-4.4.1-fuse-00-08, built with maven 3.0.3, when deploying it to apache karaf 2.2.4 and CXF 2.4.3 the web service is never published and never visible to the CXF servlet (http://localhost:8181/cxf/). There are no errors in the karaf log. How would one go about debugging such behavior?
It's worth turning up the log level(s) - you can do this permanently in the etc/org.ops4j.pax.logging.cfg or in the console with log:set TRACE org.apache.cxf - IIRC this will show some useful information.
Also check that it's actually published on localhost/127.0.0.1 - it may well be being published on another interface, the IP of the local network but not localhost. Try using 0.0.0.0 as the the address, that way it will bind to all available interfaces.
As you're using maven, you can download the CXF source (easily in Eclipse) and connect a remote debugger to the Karaf instance, with some strategically placed breakpoints you should be able to get a handle on what's going on.
Try changing to Equinox instead of the default of Felix. There is a bug in 2.4.3 in that it doesn't work well with Felix. Alternatively, CXF 2.4.4 is now available that should also fix it.
Take a look at this issue I filed this week: https://issues.apache.org/jira/browse/CXF-4058
What I found is that if my beans.xml is loaded before the cxf bundle jar, then the endpoints are registered with CXF but not with the OSGi http service. So everything looks good from the logs but the endpoints are never accessible. This is a race condition.
I did two workarounds: 1) in the short term, just move my own jars later in the boot order (I use Karaf features) so Spring and CXF are fully loaded before my beans.xml is read and 2) abandon Spring and roll my own binding code based loosely on this approach: http://eclipsesource.com/blogs/2012/01/23/an-osgi-jax-rs-connector-part-1-publishing-rest-services/
I just implemented solution #2 yesterday and I'm already extremely happy with it. It's solved all of my classloader issues (before I had to manually add a lot of Import-Package lines because BND doesn't see beans.xml references) and fixed my boot race condition.

Resources