Apache Camel 中的 SEDA、VM 和直接有什么区别? [英] What is the difference between SEDA, VM and direct in Apache Camel?

查看:46
本文介绍了Apache Camel 中的 SEDA、VM 和直接有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾与 SEDA 和 direct 合作过,我也阅读过文档.

I had worked with both SEDA and direct, and I've also read the documentation.

但我仍然无法想象 SEDA 和 direct 的用法.Vm 对我来说是新的.

But I still cannot visualize the usage of SEDA and direct. Vm is new to me.

请举例说明.

推荐答案

一个 Camel 路由可以通过至少四种不同的机制直接将数据传递给另一个.直接"是指不使用网络或某种形式的中间存储(文件、数据库).这些机制可以根据它们是否可以在 CamelContext 实例之间传递数据,以及它们是同步的还是异步的进行分组.

There are at least four different mechanisms by which one Camel route can directly pass data to another. By "directly" I mean without using a network or some form of intermediate storage (file, database). These mechanisms can be grouped according to whether they can pass data between CamelContext instances or not, and whether they are synchronous or asynchronous.

  • direct -- 单个 CamelContext,同步(块生产者)
  • SEDA -- 单个 CamelContext,异步(不阻止生产者)
  • VM -- 多个 CamelContext,异步(不阻止生产者)
  • direct-VM -- 多个 CamelContext,同步(块生产者)

直接和直接 VM 机制是同步的,从某种意义上说,生产端点会阻塞,直到消费端点及其所有其余路由逻辑完成.SEDA 和 VM 机制都在消费者上使用线程池,这样生产者发出的每个请求都会分配给池中的一个线程.这允许消费者端点及其关联的路由逻辑独立于生产者进行操作.

The direct and direct-VM mechanisms are synchronous, in the sense that the producing endpoint blocks until the consuming endpoint, and all the rest of its routing logic, is complete. The SEDA and VM mechanisms both use a pool of threads on the consumer, such that each request made by the producer is assigned to one of the threads in the pool. This allows the consumer endpoint and its associated routing logic to act independently of the producer.

在不同 Camel 上下文之间进行通信的情况下,两个 VM 端点都是必需的.在许多情况下,可以将路由组合到同一个 CamelContext 中.但是,由于模块化的原因,有时它可能是不可取的,或者是不可能的,因为某些应用程序框架使之如此.例如,我可能会在库(或组件)中实现一些 Camel 路由逻辑,目的是让其他代码使用该库.为了完整起见,这个库可能会定义一个包含各种路由的自包含 CamelContext.如果我想调用库中的 Camel 逻辑,我将需要使用 VM 或直接 VM,因为直接和 SEDA 端点不包含在 Camel 上下文之间路由所需的逻辑.

Both the VM endpoints are required in situations where communication is between different Camel contexts. In many cases it is possible to combine routes into the same CamelContext. However, it may sometimes be inadvisable, for reasons of modularity, or impossible, because some application framework makes it so. For example, I might implement some Camel routing logic in a library (or component) with the intention that the library be used by other code. To be complete, this library will probably define a self-contained CamelContext with various routes. If I want to invoke the Camel logic in the library, I will need to use VM or direct-VM, because direct and SEDA endpoints do not contain the logic needed to route between Camel contexts.

这篇关于Apache Camel 中的 SEDA、VM 和直接有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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