Apache Camel中的群集:多个JVM相同的CamelContext [英] Clustering in Apache Camel: Multiple JVMs Same CamelContext

查看:500
本文介绍了Apache Camel中的群集:多个JVM相同的CamelContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个部署在集群上的应用程序.根据环境,集群可能具有2或4个JVM. 该应用程序具有与我们在所有JVM上部署的相同的CamelContext.因此,所有JVM都具有相同的路由.对于FTP路由,这很好,因为它具有竞争力,并且只有1个JVM获取文件. 但是,在使用基于计时器的操作从数据库中获取数据时,我看到所有JVM都读取相同的记录集并完成相同的工作. 我想要的是,如果一条路线将其捡起,则其他路线不应尝试. 我为此尝试了谷歌搜索.但是,找不到最佳的方法. 是否有任何默认的驼峰组件支持此功能? 我阅读了集群

I have one application that we deploy on a cluster. The cluster might have 2 or 4 JVMs as per the environment. The application has same CamelContext which we are deploying on all the JVMs. Hence, all the JVMs have same routes. For FTP routes, that is good as it makes it competitive and only 1 JVM gets the files. However, while using timer based operation to fetch from DB, I see that all the JVMs read the same set of records and do the same job. What I want is, if one route picks it up, the other routes shouldn't try. I tried googling for this. However, couldn't find the best way to do it. Is there any default camel component which supports this? I read the clustering and load balancing on Camel Documentation, but it didn't help. JGroups and ZooKeeper are specific to type of clusters. Any help would be appreciated.

推荐答案

首先,不同部署的Camel上下文将充当独立的应用程序,而彼此之间并不了解.

First, the different deployed Camel contexts will act as standalone applications with no knowledge of each other.

如果您有多个路由来自同一来源,则该行为与组件密切相关.

The behavior if you have multiple routes consuming from the same sources is very component dependent.

  • 文件/FTP和类似文件通常具有文件锁定机制,以避免多个使用者读取同一文件.
  • 消息队列(JMS/AMQP/etc)已经内置了消息处理功能,除非您使用主题,否则每个实例都将获得一个副本.
  • 数据库和其他可轮询组件可能需要您使用仅从一个节点生成的某种信号来触发轮询.

我想最后一个是您的主要问题.可以通过几种方法来完成.它们可能设置起来有些棘手,但应该可以完成工作.

I guess the last one is your primary question. It can be done by several means. They are probably a bit tricky to setup, but should do the job.

  • A clustered Quartz scheduler. Typically requires a database that is to be shared. Read here how to configure quartz in Camel. Then you need to configure quartz.properites and the clustering properties (JDBC or whatnot). That is documented here.
  • You can have a single route running (elected among your deployed Camel instances) using ZooKeeper and route policies. Then you can either use that route and fail over to an other route in case of problems, or use that single route to emit triggers, using timer or quartz, to poll that can be distributed to all camel instances.

这篇关于Apache Camel中的群集:多个JVM相同的CamelContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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