骆驼多消费者实施问题 [英] Camel Multiple Consumers Implementation Issue

查看:25
本文介绍了骆驼多消费者实施问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个 Job Scheduler,它有 4 个消费者 A、B、C 和 D.X 类型的作业必须路由到消费者 A,类型 Y 到消费者 B,依此类推.消费者 A、B、C 和 D 将作为独立的应用程序在本地或远程运行,没有任何依赖性.

Let's say I have a Job Scheduler which has 4 consumers A, B, C and D. Jobs of type X will have to be routed to Consumer A, type Y to Consumer B and so on. Consumers A, B, C and D are to run as independent applications without any dependency, either locally or remotely.

消费者需要不同的时间来完成他们的工作,这些工作随后被路由到 Job Scheduler 进行聚合.

The consumers take varying times to complete their jobs, which are subsequently routed to the Job Scheduler for aggregation.

可能还需要其中一个消费者的克隆来共享其符合条件的工作.但是,一个作业只能处理一次.

Clones of one of the consumers may also be needed to share its eligible jobs. A job should however be processed only once.

基于内容的路由器是最好的解决方案吗?请注意,我需要自定义作业调度程序,因为它只有在消费者之间拆分作业的智能.

Is Content-based router the best solution for this? Mind you, I need the custom job scheduler, because it only has the intelligence to split up a job among the consumers.

或者有没有更好的方法来处理这个问题?我不需要代理的那些功能,比如自动切换到另一个消费者(负载平衡),以及在出现故障的情况下.

Or is there any better way to handle this? I don't require those features of the broker like automatically switching over to another consumer (load balancing) and such in case of a failure.

推荐答案

我不完全确定我是否关注您.这听起来像是异步处理的一个相当直接的场景.

I'm not completly sure that I follow you. This sounds like a rather straight forward scenario for asychronous processing.

我不确定您打算如何将这些作业发送到 Camel 应用程序,但鉴于您可以在某个地方接收它们,您可能可以继续使用基于内容的简单路由器.

I'm not sure how you plan to send these jobs to the Camel application, but given you can receive them somewhere you could probably go ahead with a simple content based router.

鉴于您对消费者的要求,我会选择 JMS 队列(使用 Apache ActiveMQ 或类似的代理中间件),每种作业类型一个队列.这样可以轻松地将消费者分发到不同的机器上,而无需真正更改代码.

Given your requirements for the consumers, I would go for JMS queues (using Apache ActiveMQ or similar broker middleware), one queue per job type. This makes it easy to distribute consumers to different machines without really changing the code.

// Central node routes
from("xxx:routeJob")
   .choice()
       .when(header("type").isEqualTo("x"))
           .to("jms:queue:processJobTypeX")
       .when(header("type").isEqualTo("y"))
           .to("jms:queue:processJobTypeY")
       .otherwise()
           .to("jms:queue:processJobTypeZ"); 

 from("jms:queue:aggregateJob")
    .bean(aggregate);

// different camel application (may be duplicated for multiple instances).
from("jms:queue:processJobTypeX")
  .bean(heavyProcessing)
  .to("jms:queue:aggregateJob");

// Yet another camel application
from("jms:queue:processJobTypeY")
  .bean(lightProcessing)
  .to("jms:queue:aggregateJob");

请重新访问您的问题以获得更好的答案:)

Please revisit your question for a better answer :)

这篇关于骆驼多消费者实施问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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