Apache Camel 中的 SEDA、VM 和 direct 有什么区别?

What is the difference between SEDA, VM and direct in Apache Camel?(Apache Camel 中的 SEDA、VM 和 direct 有什么区别?)

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

问题描述

我曾与 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,同步(块生产者)

direct 和 direct-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 或 direct-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 和 direct 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Apache Camel 中的 SEDA、VM 和 direct 有什么区别?

基础教程推荐