You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Paul Dailly <pa...@gmail.com> on 2015/01/17 20:17:45 UTC

Spring Camel Quartz cluster configuration

Hi there,

I have a Spring application which defines Camel routes triggered using
camel-quartz2 (v2.14.0). The Quartz Camel routes I have configured
successfully trigger when I run a single instance of the app (i.e
non-clustered, in-memory quartz scheduler).

However, I now want to set this up in a clustered environment, where I can
have multiple instances of my application and a single mySQL database to
store the scheduled jobs for the Camel routes. I want only a single instance
of my app to run when a triggered route fires. I started to follow  this
example
<https://github.com/apache/camel/blob/master/components/camel-quartz2/src/test/resources/org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppTwo.xml>  
from Camel's GitHub repo in order hook my Camel routes into my clustered
Quartz scheduler. However I am confused by 2 parts of the bean declarations
given in this example. The first source of confusion is the bean declaration
below:

<bean id="quartz2"
class="org.apache.camel.component.quartz2.QuartzComponent">
    <property name="scheduler" ref="scheduler"/>
  </bean>

The reference above to the "scheduler" bean is an instance of
org.springframework.scheduling.quartz.SchedulerFactoryBean. However the
QuartzComponent class's scheduler property is of type org.quartz.Scheduler.
Therefore, I receive a ClassCastException when trying to set scheduler
property to an instance of
org.springframework.scheduling.quartz.SchedulerFactoryBean.

My second source of confusion is the declaration of "schedulerContextAsMap"
map shown below:

<property name="schedulerContextAsMap">
      
      <map>
        <entry key="CamelQuartzCamelContext-camelContext"
value-ref="camelContext2"/>
      </map>
    </property>

I am using Java configuration rather than XML for my bean declarations.
Therefore, should I be setting the value of the
"CamelQuartzCamelContext-camelContext" key to be an autowired instance of my
CamelContext?

I am new to Camel/Quartz so apologies if my question is difficult to reason
about. Please let me know if you need me to provide any further information
in order to clarify my issue.

Thanks,

Paul



--
View this message in context: http://camel.465427.n5.nabble.com/Spring-Camel-Quartz-cluster-configuration-tp5761825.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Spring Camel Quartz cluster configuration

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

org.springframework.scheduling.quartz.SchedulerFactoryBean is a FactoryBean, you can get the scheduler instance by calling the getObject() method.

you need to put the camel context instance into the schedulerContextAsMap.

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On January 18, 2015 at 2:12:09 PM, Paul Dailly (pauldaillycc@gmail.com) wrote:
> Hi there,
>  
> I have a Spring application which defines Camel routes triggered using
> camel-quartz2 (v2.14.0). The Quartz Camel routes I have configured
> successfully trigger when I run a single instance of the app (i.e
> non-clustered, in-memory quartz scheduler).
>  
> However, I now want to set this up in a clustered environment, where I can
> have multiple instances of my application and a single mySQL database to
> store the scheduled jobs for the Camel routes. I want only a single instance
> of my app to run when a triggered route fires. I started to follow this
> example
>  
> from Camel's GitHub repo in order hook my Camel routes into my clustered
> Quartz scheduler. However I am confused by 2 parts of the bean declarations
> given in this example. The first source of confusion is the bean declaration
> below:
>  
> > class="org.apache.camel.component.quartz2.QuartzComponent">
>  
>  
>  
> The reference above to the "scheduler" bean is an instance of
> org.springframework.scheduling.quartz.SchedulerFactoryBean. However the
> QuartzComponent class's scheduler property is of type org.quartz.Scheduler.
> Therefore, I receive a ClassCastException when trying to set scheduler
> property to an instance of
> org.springframework.scheduling.quartz.SchedulerFactoryBean.
>  
> My second source of confusion is the declaration of "schedulerContextAsMap"
> map shown below:
>  
>  
>  
>  
> > value-ref="camelContext2"/>
>  
>  
>  
> I am using Java configuration rather than XML for my bean declarations.
> Therefore, should I be setting the value of the
> "CamelQuartzCamelContext-camelContext" key to be an autowired instance of my
> CamelContext?
>  
> I am new to Camel/Quartz so apologies if my question is difficult to reason
> about. Please let me know if you need me to provide any further information
> in order to clarify my issue.
>  
> Thanks,
>  
> Paul
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Spring-Camel-Quartz-cluster-configuration-tp5761825.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>