You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Nestor Urquiza <ne...@gmail.com> on 2012/05/21 02:28:40 UTC

Configure Camel to consume externally configured quartz jobs

Hi guys,

How can I configure Camel to consume quartz jobs that are configured outside
of camel?

I can start a persisted quartz consumer without problems. I can later
reschedule it using the quartz API and I can see the route is triggered as
expected. However when the app is restarted camel will reconfigure the job
with the cron parameter. 

If I do not supply the cron parameter I get the below:

2012-05-20 20:04:27,673 ERROR
[org.springframework.web.context.ContextLoader] -   Context initialization
failed
org.apache.camel.RuntimeCamelException: java.lang.ClassCastException:
org.quartz.SimpleTrigger cannot be cast to org.quartz.CronTrigger
	at
org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1221)
	at
org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:120)
	at
org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:240)
	at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
	at
org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:324)
	at
org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:929)
	at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467)
	at
org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
	at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
	at
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
	at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
	at
org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
	at
org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.ClassCastException: org.quartz.SimpleTrigger cannot be
cast to org.quartz.CronTrigger

One option could be to pass a parameter to tell Camel not to modify the job
if it already exists.

Another option is to provide a specific class to be invoked by quartz and
from that class to use Producer Template to invoke a Camel route. Before
going that way I want to understand if this could be a feature request that
makes sense: Allowing the Camel quartz producer to not update the persisted
quartz job.

It looks to me this should be a common request (to dynamically reconfigure
quartz producers)

Thanks in advance,

-Nestor



--
View this message in context: http://camel.465427.n5.nabble.com/Configure-Camel-to-consume-externally-configured-quartz-jobs-tp5712732.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Configure Camel to consume externally configured quartz jobs

Posted by Nestor Urquiza <ne...@gmail.com>.
@Claus I don't think it is actually a bug but a design result. According to
the documentation:


> The component uses either a CronTrigger or a SimpleTrigger. If no cron
> expression is provided, the component uses a simple trigger. If no
> groupName is provided, the quartz component uses the Camel group name.
> 



--
View this message in context: http://camel.465427.n5.nabble.com/Configure-Camel-to-consume-externally-configured-quartz-jobs-tp5712732p5712897.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Configure Camel to consume externally configured quartz jobs

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

The class cast exception sounds like a bug.
Is it possible for you to create a unit test or small sample that
demonstrates the bug, and then create a JIRA ticket with it attached?


On Mon, May 21, 2012 at 2:28 AM, Nestor Urquiza
<ne...@gmail.com> wrote:
> Hi guys,
>
> How can I configure Camel to consume quartz jobs that are configured outside
> of camel?
>
> I can start a persisted quartz consumer without problems. I can later
> reschedule it using the quartz API and I can see the route is triggered as
> expected. However when the app is restarted camel will reconfigure the job
> with the cron parameter.
>
> If I do not supply the cron parameter I get the below:
>
> 2012-05-20 20:04:27,673 ERROR
> [org.springframework.web.context.ContextLoader] -   Context initialization
> failed
> org.apache.camel.RuntimeCamelException: java.lang.ClassCastException:
> org.quartz.SimpleTrigger cannot be cast to org.quartz.CronTrigger
>        at
> org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1221)
>        at
> org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:120)
>        at
> org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:240)
>        at
> org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
>        at
> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:324)
>        at
> org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:929)
>        at
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467)
>        at
> org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
>        at
> org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
>        at
> org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
>        at
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
>        at
> org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
>        at
> org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
>        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
>        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>        at java.lang.Thread.run(Thread.java:680)
> Caused by: java.lang.ClassCastException: org.quartz.SimpleTrigger cannot be
> cast to org.quartz.CronTrigger
>
> One option could be to pass a parameter to tell Camel not to modify the job
> if it already exists.
>
> Another option is to provide a specific class to be invoked by quartz and
> from that class to use Producer Template to invoke a Camel route. Before
> going that way I want to understand if this could be a feature request that
> makes sense: Allowing the Camel quartz producer to not update the persisted
> quartz job.
>
> It looks to me this should be a common request (to dynamically reconfigure
> quartz producers)
>
> Thanks in advance,
>
> -Nestor
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Configure-Camel-to-consume-externally-configured-quartz-jobs-tp5712732.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Configure Camel to consume externally configured quartz jobs

Posted by Nestor Urquiza <ne...@gmail.com>.
Resolving this demanded interacting with Quartz directly (so far working). I
have Spring starting the scheduler at application startup and some Services
allowing to reschedule jobs from Quartz API. Then the Quartz jobs just call
a Camel trigger job that sends a message to any dynamically passed endpoint:

<code>
public class CamelTriggerJob implements StatefulJob {
    
    @Override
    public void execute(JobExecutionContext context) throws
JobExecutionException {
        CamelContext camelContext = (CamelContext)
ApplicationServletContextListener.getBean("camelContext");
        ProducerTemplate template = camelContext.createProducerTemplate();
        JobDataMap dataMap = context.getJobDetail().getJobDataMap();
        String endPoint = dataMap.getString("endPoint");
        template.sendBody(endPoint, "Activation from" +
this.getClass().getName());
    }
    
}
</code>

Criticism to the solution is greatly appreciated of course.

Thanks for your help guys! Awesome support. BTW I will be writting a
beginner tutorial after my riding soon.

Best,

-Nestor

--
View this message in context: http://camel.465427.n5.nabble.com/Configure-Camel-to-consume-externally-configured-quartz-jobs-tp5712732p5713361.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Configure Camel to consume externally configured quartz jobs

Posted by Nestor Urquiza <ne...@gmail.com>.
@James the problem with JMX is distributed code. The Camel routes will be
running in several Tomcat instances so it makes sense to use db persistence
through Quartz especially if there are modules that are not related to Camel
which can reschedule under certain conditions.

The idea of having a Camel quartz consumer that does not override the quartz
scheduling settings like a cron expression is in my opinion a right
architectural decision. Thoughts?

Thanks,
- Nestor

--
View this message in context: http://camel.465427.n5.nabble.com/Configure-Camel-to-consume-externally-configured-quartz-jobs-tp5712732p5712898.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Configure Camel to consume externally configured quartz jobs

Posted by James Carman <ja...@carmanconsulting.com>.
You could probably use JMX to runtime-reconfigure the producers, right?

On Sun, May 20, 2012 at 8:28 PM, Nestor Urquiza
<ne...@gmail.com> wrote:
> Hi guys,
>
> How can I configure Camel to consume quartz jobs that are configured outside
> of camel?
>
> I can start a persisted quartz consumer without problems. I can later
> reschedule it using the quartz API and I can see the route is triggered as
> expected. However when the app is restarted camel will reconfigure the job
> with the cron parameter.
>
> If I do not supply the cron parameter I get the below:
>
> 2012-05-20 20:04:27,673 ERROR
> [org.springframework.web.context.ContextLoader] -   Context initialization
> failed
> org.apache.camel.RuntimeCamelException: java.lang.ClassCastException:
> org.quartz.SimpleTrigger cannot be cast to org.quartz.CronTrigger
>        at
> org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1221)
>        at
> org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:120)
>        at
> org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:240)
>        at
> org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
>        at
> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:324)
>        at
> org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:929)
>        at
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467)
>        at
> org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
>        at
> org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
>        at
> org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
>        at
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
>        at
> org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
>        at
> org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
>        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
>        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>        at java.lang.Thread.run(Thread.java:680)
> Caused by: java.lang.ClassCastException: org.quartz.SimpleTrigger cannot be
> cast to org.quartz.CronTrigger
>
> One option could be to pass a parameter to tell Camel not to modify the job
> if it already exists.
>
> Another option is to provide a specific class to be invoked by quartz and
> from that class to use Producer Template to invoke a Camel route. Before
> going that way I want to understand if this could be a feature request that
> makes sense: Allowing the Camel quartz producer to not update the persisted
> quartz job.
>
> It looks to me this should be a common request (to dynamically reconfigure
> quartz producers)
>
> Thanks in advance,
>
> -Nestor
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Configure-Camel-to-consume-externally-configured-quartz-jobs-tp5712732.html
> Sent from the Camel - Users mailing list archive at Nabble.com.