camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject RE: Camel Java routes using Timer firing only once
Date Fri, 25 Jul 2014 00:53:24 GMT
It looks like in the sample code which starts camel context, you are also stopping the context.

If you want timer to run continuously, your context should always be up and running as well.

Can you also add a very long sleep command just to ensure that and test the same ?

From: mikes300 []
Sent: Thursday, July 24, 2014 11:30 PM
Subject: RE: Camel Java routes using Timer firing only once

*Hi Ravi,*
I tried, but same results.  Runs once but not again.  Here are the log
entries for it.  I even tried omitting the context.stop, no success...

7:32:12,460 INFO  [org.apache.camel.impl.DefaultCamelContext] (default
task-4) Apache Camel 2.13.1 (CamelContext: camel-1) is starting
07:32:12,461 INFO  []
(default task-4) JMX is enabled
07:32:12,473 WARN
[] (default
task-4) This CamelContext(camel-1) will be registered using the name:
camel-1-1 due to clash with an existing name already registered in
07:32:12,590 INFO  [org.apache.camel.impl.converter.DefaultTypeConverter]
(default task-4) Loaded 191 type converters
07:32:12,742 INFO  [org.apache.camel.impl.DefaultCamelContext] (default
task-4) AllowUseOriginalMessage is enabled. If access to the original
message is not needed, then its recommended to turn this option off as it
may improve performance.
07:32:12,743 INFO  [org.apache.camel.impl.DefaultCamelContext] (default
task-4) StreamCaching is not in use. If using streams then its recommended
to enable stream caching. See more details at
07:32:12,802 INFO  [org.apache.camel.impl.DefaultCamelContext] (default
task-4) Route: route1 started and consuming from:
07:32:12,808 INFO  [org.apache.camel.impl.DefaultCamelContext] (default
task-4) Total 1 routes, of which 1 is started.
07:32:12,809 INFO  [org.apache.camel.impl.DefaultCamelContext] (default
task-4) Apache Camel 2.13.1 (CamelContext: camel-1) started in 0.349 seconds
07:32:13,811 INFO  [stdout] (default task-4) 07:32:13.810 [default task-4]
DEBUG com.sial.integration.test.TestRoute - sync route try block 2
07:32:13,811 INFO  [org.apache.camel.impl.DefaultCamelContext] (default
task-4) Apache Camel 2.13.1 (CamelContext: camel-1) is shutting down
07:32:13,812 INFO  [org.apache.camel.impl.DefaultShutdownStrategy] (default
task-4) Starting to graceful shutdown 1 routes (timeout 300 seconds)
07:32:13,827 INFO  [org.apache.camel.impl.DefaultShutdownStrategy] (Camel
(camel-1) thread #1 - ShutdownTask) Waiting as there are still 1 inflight
and pending exchanges to complete, timeout in 300 seconds.
07:32:14,830 INFO  [org.apache.camel.impl.DefaultShutdownStrategy] (Camel
(camel-1) thread #1 - ShutdownTask) Route: route1 shutdown complete, was
consuming from: Endpoint[timer://foo?fixedRate=true&period=1000]
07:32:14,831 INFO  [org.apache.camel.impl.DefaultShutdownStrategy] (default
task-4) Graceful shutdown of 1 routes completed in 1 seconds
07:32:14,838 INFO  [org.apache.camel.impl.DefaultCamelContext] (default
task-4) Apache Camel 2.13.1 (CamelContext: camel-1) uptime 2.379 seconds
07:32:14,839 INFO  [org.apache.camel.impl.DefaultCamelContext] (default
task-4) Apache Camel 2.13.1 (CamelContext: camel-1) is shutdown in 1.027

If it matters, I am calling the route from a bean injected into a REST call.
See below.*

package com.sial.integration.test;

import javax.inject.Inject;
import org.apache.logging.log4j.Logger;

public class TestRouteInvoker{

        /** The logger. */
    Logger logger;

*    @Inject
    TestRoute TestRoute;*

        public String putMessage() {
                logger.debug("/TestRouteInvoker/Start ok");
                return "/TestRouteInvoker/Start ok";

*And then the route class:*

package com.sial.integration.test;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.logging.log4j.Logger;
import java.util.*;
import javax.inject.Inject;

public class TestRoute {

        /** The logger. */
    Logger logger;

        public void createRoute() {
               CamelContext context = new DefaultCamelContext();
               logger.debug("I am in the SYNC route");

                        logger.debug("sync route try block 1");

                context.addRoutes(new RouteBuilder() {
                    public void configure() {
is " + new Date())).to("file:target/reports/?fileName=date.txt");

from("timer://foo?fixedRate=true&period=1000").setBody(constant("Time is " +
new Date())).to("file:target/reports/?fileName=date.txt");*

                catch(Exception e){
                    logger.debug("Exception thrown  :" + e);


                        logger.debug("sync route try block 2");

                // stop the CamelContext
                        catch(Exception e){
                                logger.debug("Exception thrown  :" + e);



View this message in context:
Sent from the Camel - Users mailing list archive at
This e-mail and any files transmitted with it are for the sole use of the intended recipient(s)
and may contain confidential and privileged information. If you are not the intended recipient(s),
please reply to the sender and destroy all copies of the original message. Any unauthorized
review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or
any action taken in reliance on the contents of this e-mail is strictly prohibited and may
be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications
sent to and from Cognizant e-mail addresses may be monitored.

View raw message