Apache Camel 生产者和消费者 [英] Apache Camel producers and consumers

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

问题描述

我很难理解这个概念.

我正在尝试实现一个端点,该端点侦听专有格式的传入消息的 tcp 端口,然后转换消息并让骆驼接管转发和路由.

I am trying to implement an endpoint that listens on a tcp port for incoming messages in a proprietary format, which would then transform the message and have camel take over the forwarding and routing.

我是否正确理解生产者负责将消息发送到 EndpointConsumer 从该端点接收它们?

Did I understand correctly that that the Producer is responsible for sending messages into the Endpoint and the Consumer receives them from that endpoint?

在研究接口时,我无法弄清楚这些对象之间的消息流,尤其是在消费者部分.Consumer 只定义了 start()stop() 方法...

When studying the interfaces I couldn't figure out the message flow between those objects, especially on the consumer part. Consumer only defines start() and stop() methods...

在框架实现上设置测试时,Camel 在端点上调用了 createProducer(),在生产者对象上调用了 process().之后它返回,没有对消费者或与之关联的处理器做任何事情.

When setting up a test on a skeleton implementation, Camel invoked createProducer() on the endpoint and process() on the producer object. After that it returned, swithout doing anything with the consumer or the processor associated with it.

有人能指出我正确的方向吗?

Could someone point me in the right direction?

推荐答案

我终于通过查看 Stream 组件弄清楚了.

I finally figured it out by looking at the Stream component.

事实证明,我错误地认为端点是一切都必须通过的中心.

Turns out that I made the mistake of thinking about the endpoint as something central thru which everything must go.

简单的答案是消费者从外部系统接收数据(在我的例子中监听服务器套接字),生产者将数据发送到外部系统.

The simple answer is that the consumer receives data from an external system (listening on a server socket in my case) and the producer sends data to the external system.

由于我的端点是只读的(它不会用作 Camel 路由过程的最终目的地),我真的不需要生产者(如果系统由于配置错误仍然尝试这样做,它应该抛出 RuntimeException).一个合适的例子是骆驼原子端点 - 您可以阅读提要,但(从 1.6.0 开始)您不能发布一个.

Since my endpoint is read-only (it will not be used as the final destination of Camel routing process), I really do not need a producer (it should throw a RuntimeException if the system still tries to do it due to misconfiguration). A fitting example would be the camel-atom endpoint - you can read feeds but (as of 1.6.0) you cannot publish one.

同样,对于不从外部系统(例如日志记录)接收数据的只写端点,您只需要一个生产者.

Likewise, you only need a producer for a write-only endpoint which does not receive data from an external system (e.g logging).

这篇关于Apache Camel 生产者和消费者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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