java 骆驼路线和端点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7728260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 21:10:09  来源:igfitidea点击:

Camel Routes and Endpoints

javaroutesapache-camelendpoint

提问by IAmYourFaja

I've been poring over the Apache Camel docs trying to get a concrete understanding of two of its most basicconcepts (endpoints and routes), and although these terms are used everywhere throughout the docs, I can find no reference that actually defines what they are and what they are used for. And although their names are fairly obvious-sounding, and I thinkI understand what they are, I've now been assigned to a task that has landed me neck-deep in Apache Camel Land, and its absolutely vital that I understand what these mechanisms are.

我一直在仔细研究 Apache Camel 文档,试图具体了解其两个最基本的概念(端点和路由),尽管这些术语在整个文档中随处可见,但我找不到实际定义它们的参考资料是以及它们的用途。虽然他们的名字听起来很明显,而且我我明白他们是什么,但我现在被分配到一项任务,让我深入到 Apache Camel Land,我了解这些机制是什么绝对重要的是。

My guess is that an "endpoint" is just a bean - one that can be configured in a config file like any other - that maps a name to a URI/port combo (this taken from the W3C docs). In the context of Apache Camel, my guessis that endpoints are used to connect components together, so that "routes" (connections/maps) can be formed between them. So when Component A living at Endpoint 1 wants to communicate with Component B living at Endpoint 2, so long as there is a mapping from 1 to 2, Camel will be able to transmit messages between these two.

我的猜测是“端点”只是一个 bean - 一个可以像其他任何其他配置一样在配置文件中配置的 bean - 它将名称映射到 URI/端口组合(这取自 W3C 文档)。在 Apache Camel 的上下文中,我的猜测是端点用于将组件连接在一起,以便在它们之间形成“路由”(连接/映射)。所以当居住在端点 1 的组件 A 想要与居住在端点 2 的组件 B 通信时,只要有从 1 到 2 的映射,Camel 就可以在这两者之间传输消息。

Please stop me and correct me if I am wrong here!

如果我在这里错了,请阻止我并纠正我!

So now, I've seen examples where it looks like routes can be configured in Java:

所以现在,我看到了一些看起来可以在 Java 中配置路由的示例:

from("endpointA").routeId("someMessage").to("endpointB");

And I've seen examples where it looks like routes can be configured in XML:

我已经看到一些示例,其中路由可以在 XML 中配置:

<route id="">
    <from .../>
    <to .../>
</route>

Are these two methods for configuring routes, or are they different concepts altogether?

这两种配置路由的方法,还是完全不同的概念?

Finally, what is the format of the messages that can be routed between endpoints?If it has to be XML, for example, what is the XSD/schema of these routed messages? If it has to be a Java object, what bounds/restrictions apply to the objects that Camel can send?

最后,可以在端点之间路由的消息的格式是什么?例如,如果它必须是 XML,那么这些路由消息的 XSD/模式是什么?如果它必须是 Java 对象,那么 Camel 可以发送的对象有哪些限制/限制?

采纳答案by Mike Pone

It seems like you are getting a decent grasp of the concept. I think it helps to think about endpoints in more abstract terms. The camel documentationis not much help here. Endpoints can be thought of as interfaces to a component. Each component can have 1 or more endpoints configured. It helps me to think about endpoints within the context of a route. A simple route can go from Endpoint A (This could be a JMS Queue, tcp socket, file or any camel component) and go to Endpoint B (which can be any camel component). You can of course have processors in the route too that transform the data.

看起来你对这个概念有了很好的理解。我认为用更抽象的术语来考虑端点会有所帮助。在骆驼的文档是没有多大帮助这里。端点可以被认为是组件的接口。每个组件可以配置 1 个或多个端点。它帮助我考虑路由上下文中的端点。一个简单的路由可以从端点 A(这可以是 JMS 队列、tcp 套接字、文件或任何骆驼组件)到端点 B(可以是任何骆驼组件)。当然,您也可以在路由中使用处理器来转换数据。

The two examples of route creation you give are just that, two ways to create a route. They are the examples of the same concept. The first being Java DSL and the second using XML.

您提供的两个路线创建示例就是创建路线的两种方法。它们是同一概念的示例。第一个是 Java DSL,第二个是使用 XML。

The format of the messages is typically XML, and the XML can be any valid XML and does not need to be tied to an XSD. The message can also be any Java object. As long as it is staying in the JVM (ie, not going over a socket) it doesn't need to be serializeable.

消息的格式通常是 XML,XML 可以是任何有效的 XML,不需要绑定到 XSD。消息也可以是任何 Java 对象。只要它留在 JVM 中(即,不通过套接字),它就不需要可序列化。

回答by Mike Pone

Route is an ordered combination of processing steps

路由是处理步骤的有序组合

Endpoint represents the beginning or end of a route (for the most part), that other routes might connect to as their beginning/end or might back onto an external system (e.g. JMS, email, etc.)

端点表示路由的开始或结束(大部分),其他路由可能连接到作为其开始/结束或可能返回到外部系统(例如 JMS、电子邮件等)