- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
Camel in Action
一书中生产者和消费者的定义让我有点困惑。我已经阅读了类似问题的其他两个答案,但我仍然觉得不是那样。
A producer is the Camel abstraction that refers to an entity capable of creating and sending a message to an endpoint. Figure 1.10 illustrates where the producer fits in with other Camel concepts. When a message needs to be sent to an endpoint, the producer will create an exchange and populate it with data compatible with that particular endpoint. For example, a
FileProducer
will write the message body to a file. AJmsProducer
, on the other hand, will map the Camel message to ajavax.jms.Message
before sending it to a JMS destination. This is an important feature in Camel, because it hides the complexity of interacting with particular transports.A consumer is the service that receives messages produced by a producer, wraps them in an exchange, and sends them to be processed. Consumers are the source of the exchanges being routed in Camel. Looking back at figure 1.10, we can see where the consumer fits in with other Camel concepts. To create a new exchange, a consumer will use the endpoint that wraps the payload being consumed. A processor is then used to initiate the routing of the exchange in Camel using the routing engine.
实际上是谁在创建交易所?生产者和消费者在典型的沟通 channel 的哪一边?从上面的文字我真的不能说谁对此负责。如果有人可以提供图片(我不清楚书中的图片),生产者和消费者的确切位置并以简单的方式解释它们的工作方式,那就太好了。也许一些例子也会有用。
好的,也许最好举个例子,有人可以告诉我它是如何工作的。想象一下,我们想要从文件夹中获取文件并将它们放入 JMS 队列中,然后从发送它们进行进一步处理,最终保存在磁盘上。
根据我的图片,生产者、消费者到底在哪里?我意识到什么是组件和端点。
最佳答案
您的怀疑或多或少是正确的。举个简单的例子:
CamelContext camelContext = new DefaultCamelContext();
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() {
from("file:data/inbox?noop=true") // consumer
.to("file:data/outbox"); // producer
}
});
camelContext.start();
Thread.sleep(2000);
camelContext.stop();
在这个例子中,我们使用了一个RouteBuilder
来创建一个Route
,一旦CamelContext
启动,它会执行如下:
FileComponent
来表示这两个位置。FileEndpoint
。FileConsumer
用于从 data/inbox
中读取数据。GenericFileProducer
以写入 data/outbox
。FileConsumer
以开始从其目录中轮询文件,该目录指示其 Endpoint
创建一个 Exchange
(如正确所示图片)。 GenericFileMessage
绑定(bind)到此 Exchange
。Exchange
被交给了FileProducer
。从这个角度来看,Consumer
没有创建交换。我想,在本书的这个阶段,它还没有意义。这反射(reflect)在文本中。但是,查看实现,当您查看代码时两者是等价的:
Consumer
在发送消息时使用一些 Processor
,在这种情况下,由 Consumer
表示,然后由 Consumer
生成一个 Exchange
,Consumer
查询它的 Endpoint
然后创建实际的 Exchange
.
关于java - Camel 生产者消费者困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27594006/
我创建了一个 spring-boot 应用程序,我在其中使用 camel-reSTLet 组件将我的 camel 路由公开为 rest 端点。 我的 camel 路由很简单:它们接受来自北向休息端点的
我有一条路由 (route1),它将数据发送到 HTTP 端点。为此,它必须设置授权 header 。 header 值每小时超时一次,必须更新。 为此,我创建了另一个路由 (route2),它使用提
我正在使用 camel-cdi,它正在注入(inject) CamelContext,检测项目中的所有路由。但是我想要一个带有注册表的 CamelContext,因为我有一些在 Camel route
我想使用来自网络服务的数据并将其放入 Camel eh-cache 中。后来我想通过 CacheManager 在 Camel 上下文之外使用这个缓存。我没有找到任何方法。 在下面的代码中,我跳过了
问题描述: 我无法从我的 Camel servlet 路由到 cxfbean。路由初始化失败并显示以下错误消息: "Failed to create route route1 at: >>> To[c
我想了解 Camel 中的工作单元概念。我有一个简单的问题,希望这里有人可以提供帮助。 例如,如果路由 Exchange 涉及多个路由 from("aws-sqs:Q1").to("direct:pr
首先是我正在尝试做的事情的基本轮廓 我有一个 MQ,我想从 读取消息 预处理 XML,并在 Exchange 上设置属性 发出 HTTP 请求 处理来自 http 请求和初始交换中的属性的数据 将其放
我有一个 SFTP 路由(在 Spring XML 中),它的 from 路径以每日更改的目录(即/yyyyMMdd)结尾,并且在 autoCreate=true 时一切正常或者路径开始时目录存在。但
如何用 Camel 实现这样的过程: 拆分 处理每个拆分的项目 聚合结果 如果发生异常: 停止 split 返回异常前所有item的聚合结果及异常信息 split时定义.stopOnException
我在 Camel 中有一条路线,我想在发生异常时重试,但我想设置一个属性,以便路线第二次可以做一些稍微不同的事情,以尝试阻止错误在重试时再次发生。这是说明我目前正在尝试的想法的路线。 from("di
这两个有何不同 from(endpoint).to(endpoint:a, endpoint:b) from(endpoint).multicast().to(endpoint:a, endpoint
我的 Camel 路线如下(示例) from (activemq:xyz) --- 从 QUEUE 接收消息 to(smpp:abc) --- 提交短信至短信中心 to(cxf:hij) --- 基于
我的 Camel 路线如下(示例) from (activemq:xyz) --- 从队列接收消息 to(smpp:abc) --- 将消息提交给 SMSC to(cxf:hij) --- 基于 SM
当捕获异常时,有什么方法可以停止路由执行(显示日志消息后)? java.lang.IllegalA
我正在使用 Camel 进行集成。我有一个用例,其中 Camel 应该将 1 条消息从一个队列传输到另一个队列,但它不断向队列发送相同的消息。请查看我的以下路线: ProducerTemplate正在
当异常在多播内部抛出时,Camel 不会传播异常。 考虑到以下设置,其中 direct:route 从其 beanRef 抛出异常: rest("/...") .pos
有没有办法使用生产者模板设置 Camel 交换属性? 想象一个接收客户订单的休息端点(尚未在 Camel route )。使用生产者模板,我想 在交易所上设置客户 ID 属性。 稍后在路由 需要时使用
再见,我的基本要求是有一个可以发送消息的路由,并将其放在 JMS 队列中。 camel 上下文在 JavaEE 6 容器中运行,即 JBoss AS 7.1.1,因此它是 HornetQ for JM
Camel 2.23.1 Karaf 4.2.4 白羊座蓝图(用于注册所有内容的外部容器) Camel 蓝图(用于 Camel 路线) Camel CXF(用于 rsServer) CXF 核心(用于
现在我在 Java EE 7 应用程序上使用 JMS 2.0 和 Artemis 1.2.0,我想用 Camel 做一些集成任务。 现在查看 camel-jms 文档,没有提及如何使用通用的 came
我是一名优秀的程序员,十分优秀!