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

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

问题描述

我有一个应用程序部署在集群上.根据环境,集群可能有 2 或 4 个 JVM.该应用程序具有我们在所有 JVM 上部署的相同 CamelContext.因此,所有 JVM 都有相同的路由.对于 FTP 路由,这很好,因为它具有竞争力,并且只有 1 个 JVM 获取文件.但是,在使用基于计时器的操作从数据库中获取数据时,我发现所有 JVM 都读取相同的记录集并执行相同的工作.我想要的是,如果一条路线捡起来,其他路线不应该尝试.我试着用谷歌搜索这个.但是,找不到最好的方法来做到这一点.是否有任何默认的骆驼组件支持这个?我阅读了 集群负载平衡 在 Camel 文档上,但没有帮助.JGroups 和 ZooKeeper 特定于集群类型.任何帮助将不胜感激.

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.

  • 集群 Quartz 调度器.通常需要一个要共享的数据库.在此处阅读如何在 Camel 中配置 quartz.然后您需要配置quartz.properites 和集群属性(JDBC 或诸如此类).这是记录在此.
  • 您可以使用 ZooKeeper 和路由策略.然后,您可以使用该路由并在出现问题时故障转移到另一条路由,或者使用该单个路由发出触发器,使用计时器或石英,以轮询可以分发到所有骆驼实例.
  • 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天全站免登陆