在集群环境中将Quartz与Mule一起使用 [英] Using Quartz with Mule in Clustered Environment

查看:87
本文介绍了在集群环境中将Quartz与Mule一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我试图从Yelp API中读取数据,并希望在一定间隔后将其放入ActiveMQ队列中,所以我使用了相同的石英调度程序.我的石英调度程序每10分钟运行一次,将数据推送到队列, 到这里一切都很好,

I have a scenario where , I am trying to read data from Yelp API and want to put it into a ActiveMQ queue after certain intervals, So I am using quartz scheduler for the same.My quartz scheduler runs after every 10 minutes and pushes the data to queue, All is fine till here,

现在,我希望它在集群环境中工作,在那里我将部署2个实例并侦听相同的Yelp端点,现在发生的是,我来自2个实例的石英调度程序正在同一实例上执行,并且它们提取相同的信息来自Yelp,导致相同的消息落入ActiveMQ队列中,即DUPLICATES(我想将群集环境用于高可用性目的,即,如果某个节点发生故障,则其他节点可以接管.)

Now I want this to work in a clustered environment, where I will have 2 instances deployed and listening to same Yelp Endpoint , Now what is happening is, my quartz scheduler from 2 instances are executing at same instance and they extract same information from Yelp ,causing same messages to land up in ActiveMQ queue, that is DUPLICATES,(I want to use clustered environment for High availability purposes, i.e. if any node fails other node can takeover.)

Mule中有任何配置可以将一个节点提升为主节点,将另一个提升为故障转移节点.

So is there any configuration, in Mule which can promote one node as master and other as failover node.

感谢所有帮助!

推荐答案

这将由cron表达式0/10 * * * * ?触发(每10秒),用于运行相同应用程序并连接到相同数据库(MySQL)的所有节点之一在这种情况下). Quartz的设置有点混乱.您需要配置数据库等,但是我让您继续学习Quartz文档.您应该查看版本1.8.x,而不是版本2.x.

This will trigger by the cron expression 0/10 * * * * ? (each 10th second) for one of all nodes running the same application and that connects to the same database (MySQL in this case). The Quartz setup is a bit messy. You need to configure the database etc, but I leave you studying the Quartz docs for that. You should look at version 1.8.x and not 2.x.

这在Mule EE中几乎是群集端点的一种预算替代方案.当您不想群集EE节点或需要运行CE节点时,这很有用.

It's pretty much a budget alternative of clustering endpoints in Mule EE. It's useful when you do not want to cluster your EE nodes or need to run CE nodes.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd">

    <quartz:connector name="quartzConnector" validateConnections="true" doc:name="Quartz">
        <quartz:factory-property key="org.quartz.scheduler.instanceName" value="QuartzScheduler" />
        <quartz:factory-property key="org.quartz.scheduler.instanceId" value="AUTO" />
        <quartz:factory-property key="org.quartz.jobStore.isClustered" value="true" />
        <quartz:factory-property key="org.quartz.scheduler.jobFactory.class" value="org.quartz.simpl.SimpleJobFactory" />
        <quartz:factory-property key="org.quartz.threadPool.class" value="org.quartz.simpl.SimpleThreadPool" />
        <quartz:factory-property key="org.quartz.threadPool.threadCount" value="3" />
        <quartz:factory-property key="org.quartz.scheduler.rmi.proxy" value="false" />
        <quartz:factory-property key="org.quartz.scheduler.rmi.export" value="false" />

        <quartz:factory-property key="org.quartz.jobStore.class" value="org.quartz.impl.jdbcjobstore.JobStoreTX" />
        <quartz:factory-property key="org.quartz.jobStore.driverDelegateClass" value="org.quartz.impl.jdbcjobstore.StdJDBCDelegate" />
        <quartz:factory-property key="org.quartz.jobStore.dataSource" value="quartzDataSource" />
        <quartz:factory-property key="org.quartz.jobStore.tablePrefix" value="QRTZ_" />

        <quartz:factory-property key="org.quartz.dataSource.quartzDataSource.driver"  value="com.mysql.jdbc.Driver" />

        <quartz:factory-property key="org.quartz.dataSource.quartzDataSource.URL" value="jdbc:mysql://localhost:3306/qrtz" />
        <quartz:factory-property key="org.quartz.dataSource.quartzDataSource.user" value="root" />
        <quartz:factory-property key="org.quartz.dataSource.quartzDataSource.password"  value="" />
        <quartz:factory-property key="org.quartz.dataSource.quartzDataSource.maxConnections"  value="8" /> 

    </quartz:connector>

    <flow name="cFlow1">
        <quartz:inbound-endpoint jobName="job1" cronExpression="0/10 * * * * ?" repeatInterval="0" connector-ref="quartzConnector" responseTimeout="10000" doc:name="Quartz">
            <quartz:event-generator-job>
                <quartz:payload>Job Trigger</quartz:payload>
            </quartz:event-generator-job>
        </quartz:inbound-endpoint>
        <logger level="INFO" message="Got message" doc:name="Logger"/>
    </flow>        
</mule>

这篇关于在集群环境中将Quartz与Mule一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆