简体   繁体   English

何时使用 Spring Integration 与 Camel?

[英]When to use Spring Integration vs. Camel?

As a seasoned Spring user I was assuming that Spring Integration would make the most sense in a recent project requiring some (JMS) messaging capabilities ( more details ).作为一个经验丰富的 Spring 用户,我假设 Spring Integration 在最近需要一些 (JMS) 消息传递功能的项目中最有意义( 更多详细信息)。 After some days working with Spring Integration it still feels like a lot of configuration overhead given the amount of channels you have to configure to bring some request-response (listening on different JMS queues) communications in place.在使用 Spring Integration 几天后,考虑到您必须配置的通道数量,以实现一些请求-响应(侦听不同的 JMS 队列)通信,它仍然感觉像很多配置开销。

Therefore I was looking for some background information how Camel is different from Spring Integration, but it seems like information out there are pretty spare, I found:因此,我正在寻找 Camel 与 Spring Integration 有何不同的一些背景信息,但似乎那里的信息非常少,我发现:

Question is: what experiences did you make on using the one stack over the other?问题是:在使用一个堆栈而不是另一个堆栈时,您有什么经验? In which scenarios would you recommend Camel were Spring Integration lacks support?如果 Spring Integration 缺乏支持,您会在哪些场景中推荐 Camel? Where do you see pros and cons of each?你从哪里看出各自的优缺点? Any advise from real-world projects are highly appreciated.任何来自现实世界项目的建议都受到高度赞赏。

We choose Camel over Spring-Integration because the fluent API is really nice.我们选择 Camel 而不是 Spring-Integration,因为 fluent API 非常好。 We actually use it in Spring projects and use Spring to configure part of it.我们实际上在Spring项目中使用它,并使用Spring来配置它的一部分。 The programming API's are clear and there is a large set of sensible components.编程 API 很清楚,并且有大量合理的组件。

We did a small scale shootout and basically at that time for our requirement Camel won.我们进行了一次小规模的枪战,当时基本上满足了我们的要求,Camel 赢了。 We use it mainly to transfer internal datafiles to/from external parties which usually requires format conversions sending it using ftp/sftp/... or attaching it to an email and sending it out.我们主要使用它来向/从外部各方传输内部数据文件,这通常需要使用 ftp/sftp/... 发送它或将其附加到电子邮件并发送出去。

We found the edit-compile-debug cycle reduced.我们发现编辑-编译-调试周期减少了。 Using groovy to experiment setting up routes are added bonuses.使用 groovy 来试验设置路由是额外的好处。

Spring-Integration is a great product too, and I am quite sure it would satisfy our needs too. Spring-Integration 也是一个很棒的产品,我很确定它也能满足我们的需求。

I only recommend Spring Integration if you already have got a Spring project and you have just to add some "basic" integration using File, FTP, JMS, JDBC, and so on.如果您已经有一个 Spring 项目,并且您只需使用 File、FTP、JMS、JDBC 等添加一些“基本”集成,我只推荐 Spring Integration。

Apache Camel has two main advantages: Apache Camel 有两个主要优点:

  1. Many, many more technologies are supported.支持更多的技术。
  2. Besides, a (good) XML DSL, there are fluent APIs for Java, Groovy and Scala.此外,一个(好的)XML DSL,还有适用于 Java、Groovy 和 Scala 的流畅 API。

Because Apache Camel has very good integration with Spring, I would even use it instead of Spring Integration in most Spring projects.因为 Apache Camel 与 Spring 的集成非常好,我什至会在大多数 Spring 项目中使用它来代替 Spring Integration。

If you need more details, you can read my experiences in my blog post: Spoilt for Choice: Which Integration Framework to use – Spring Integration, Mule ESB or Apache Camel?如果您需要更多详细信息,可以在我的博客文章中阅读我的经验: Spoiled for Choice: which Integration Framework to use – Spring Integration、Mule ESB 或 Apache Camel?

I have recently conducted a Camel vs Spring Integration shoot-out with the aim to integrate Apache Kafka .我最近进行了 Camel 与 Spring Integration 的较量,目的是集成Apache Kafka Despite being an avid Spring developer, I sadly found my suspicion with Spring's ever-growing Project stack confirmed: Spring is awesome as IOC-Container to serve as glue for other framework, but it fails at providing viable alternatives to those frameworks .尽管我是一名狂热的 Spring 开发人员,但遗憾的是,我发现我对 Spring 不断增长的项目堆栈的怀疑得到证实: Spring 作为 IOC-Container 作为其他框架的粘合剂非常棒,但它未能这些框架提供可行的替代方案 There might be exceptions to this, namely everything to do with MVC, where Spring came from and where it does a great job, but other attempts to provide new functionality on top of container features fall short for three reasons and the SI Kafka use case confirms all of them:可能有例外,即与 MVC 相关的所有事情,Spring 来自何处以及它在何处做得很好,但其他在容器特性之上提供新功能的尝试由于三个原因而失败, SI Kafka 用例证实了这一点他们都:

  • Introduction of a long-winded difficult to use DSL for XML-configuration.为 XML 配置引入一个冗长难用的 DSL。
  • Pages of xml-configuration code to get all framework components wired-up.用于连接所有框架组件的 xml 配置代码页。
  • Missing resources to provide functionality on par with dedicated frameworks.缺少提供与专用框架相当的功能的资源。

Now, back to the results of my shoot-out: most importantly I am impressed by Camels overall concept of routes between endpoints .现在,回到我的枪战结果:最重要的是,Camels 的端点之间路由的整体概念给我留下了深刻的印象。 Kafka seamlessly integrates with this concept and three lines of configuration are enough to get everything up-and-running. Kafka 与这个概念无缝集成,三行配置足以让一切正常运行。 Problems encountered during the process are neatly addressed by ample documentation from the project team as well as a lot of questions on Stackoverflow.项目团队提供大量文档以及有关 Stackoverflow 的大量问题巧妙地解决了在此过程中遇到的问题。 Last but not least, there is a comprehensive integration into Spring that leaves no wishes unfulfilled.最后但并非最不重要的一点是,它与 Spring 进行全面集成,没有遗漏任何愿望。

With SI on the contrary, the documentation for the Kafka integration is quite intense and still fails to explain clearly how to integrate Kafka.与SI相反,Kafka集成的文档相当密集,仍然没有解释清楚如何集成Kafka。 The integration of Kafka is pressed into the SI-way of doing things, which adds extra complexity. Kafka 的集成被入了 SI 的处事方式,这增加了额外的复杂性。 Other documentation, eg on Stackoverflow is also less plentiful and less helpful than for Camel.其他文档,例如 Stackoverflow 上的文档也没有 Camel 那样丰富和有用。

My conclusion: cobbler stick to your trade - use Spring as a container and Camel as system integration framework.我的结论是:cobbler 坚持你的交易——使用 Spring 作为容器,使用 Camel 作为系统集成框架。

It really depends on what you want to do.这真的取决于你想做什么。 If you need to extend something to build your own messaging solution Spring Integration has the better programming model.如果你需要扩展一些东西来构建你自己的消息传递解决方案,Spring Integration 有更好的编程模型。 If you need something that supports many protocols without custom code, Camel is ahead of Spring Integration.如果您需要无需自定义代码即可支持多种协议的东西,Camel 领先于 Spring Integration。

Having a small scale shootout is a very good idea, just make sure you're trying to do the type of things that you'd typically be doing in the project.进行小规模的枪战是一个很好的主意,只要确保您正在尝试做您在项目中通常会做的事情。

--disclaimer: I'm a Spring Integration committer --disclaimer: 我是 Spring 集成提交者

Most comparisons of Camel and SI that I've seen don't take the following into account:我见过的 Camel 和 SI 的大多数比较都没有考虑以下因素:

1.) The effect that Spring Boot has had on developer productivity for Spring Integration 1.) Spring Boot 对 Spring Integration 开发人员生产力的影响

2.) The effect of Spring XD has had on making Spring Integration applications available with no code compilation - also Spring XD sources and sinks are simply Spring Integration channel adapters, when you're looking to extend Spring XD. 2.) Spring XD 的影响使 Spring Integration 应用程序无需代码编译即可使用 - 当您希望扩展 Spring XD 时,Spring XD 源和接收器也只是 Spring Integration 通道适配器。

3.) The effect of Spring XD has had on making unifying Spring Integration, Spring Batch, Spring Data (+Hadoop!) in one stack, effectively bringing batch and stream processing, HDFS/Apache Hadoop support, and much more to Spring Integration. 3.) Spring XD 的作用是将 Spring Integration、Spring Batch、Spring Data(+Hadoop!)统一在一个堆栈中,有效地为 Spring Integration 带来了批处理和流处理、HDFS/Apache Hadoop 支持等。

4.) The effect of the soon-to-be-released Spring Integration 4.0 Java DSL https://github.com/spring-projects/spring-integration-extensions/wiki/Spring-Integration-Java-DSL-Reference 4.) 即将发布的 Spring Integration 4.0 Java DSL 的效果https://github.com/spring-projects/spring-integration-extensions/wiki/Spring-Integration-Java-DSL-Reference

For your consideration,供您考虑,

/Pieter (disclaimer I work at Pivotal) /Pieter(免责声明我在 Pivotal 工作)

We are using Spring Integration for our application and now considering to move to Apache Camel as we encountered lots of issues with Spring Integration framework.我们正在为我们的应用程序使用 Spring Integration,现在考虑迁移到 Apache Camel,因为我们在 Spring Integration 框架中遇到了很多问题。 Here are couple of issues.这里有几个问题。

  1. The CachingConnectionFactory which Spring provides opens 1000's of idle connections in IBM MQ and there is no guarantee that these connections are reused. Spring 提供的 CachingConnectionFactory 在 IBM MQ 中打开了 1000 个空闲连接,并且不能保证这些连接被重用。 And still these connections will stay open forever which creates troubles on the MQ side.而且这些连接将永远保持打开状态,这会在 MQ 端造成麻烦。 Had to restart the application every week in lower environments just to refresh the connections.必须每周在较低环境中重新启动应用程序才能刷新连接。 Apache Camel also provides Caching and the connections seems to go up/down based on the load. Apache Camel 还提供缓存,连接似乎根据负载上升/下降。

  2. Spring doesn't provide mappers for QoS parameters. Spring 不提供 QoS 参数的映射器。 Even if you enable QoS, the delivery mode and expiration/timetolive properties will get lost (I am going to raise a JIRA issue for this).即使您启用 QoS,交付模式和到期/生存时间属性也会丢失(我将为此提出 JIRA 问题)。 Apache Camel handles this and QoS parameters are sent to upstream applications and not dropping it. Apache Camel 处理这个问题,QoS 参数被发送到上游应用程序而不是丢弃它。

I am right now working on issues with handling the exceptions and transactions with Apache Camel which Spring seemed to handle better with AOP.我现在正在处理使用 Apache Camel 处理异常和事务的问题,Spring 似乎可以用 AOP 更好地处理这些问题。

Apache Camel is a very good framework and very complete too. Apache Camel 是一个非常好的框架,也非常完整。 But if your application uses spring, my personal advice is to use Spring Integration.但是如果您的应用程序使用 spring,我个人的建议是使用 Spring Integration。

Spring Integration is the integration EIP complaint framework of Spring-Source ecosystem. Spring Integration 是 Spring-Source 生态的集成 EIP 投诉框架。 It has excellent integration with the ecosystem: Spring boot, Batch, XD;它与生态系统有很好的整合:Spring boot、Batch、XD; even the core uses same abstraction starting from Spring Framework 4. Some of the messaging abstraction were moved in the framework, as proof that the basic messaging abstraction of Spring Integration is very strong.甚至核心使用从 Spring Framework 4 开始的相同抽象。框架中移动了一些消息抽象,以证明 Spring Integration 的基本消息抽象非常强大。 Now Spring framework for instance use the messaging abstraction for Spring Web, web socket support.现在 Spring 框架例如使用 Spring Web 的消息传递抽象,Web 套接字支持。

Another good thing in a Spring application with Spring integration respect to use Apache Camel is that with Spring integration, you can use only one Application Context.与使用 Apache Camel 的 Spring 集成的 Spring 应用程序中的另一个好处是,使用 Spring 集成,您只能使用一个应用程序上下文。 Remember that the Camel Context is a Spring context.请记住,Camel 上下文是一个 Spring 上下文。 if you have the chance of use a new Spring version, I suggest to use Spring Integration Java DSL for configuration.如果您有机会使用新的 Spring 版本,我建议使用 Spring Integration Java DSL 进行配置。 I use it on my new projects, and it feels more readable and clear.我在我的新项目中使用它,感觉更易读和清晰。 I hope that this reflection can help you for the your evaluations.我希望这个反思可以帮助您进行评估。

Actually, I would say FTP has graduated its incubation period.实际上,我会说 FTP 已经结束了它的孵化期。 You can do a simple search on SI forums/JIRA to see what new features were implemented and bugs that were fixed.您可以在 SI 论坛/JIRA 上进行简单的搜索,以查看实现了哪些新功能以及修复了哪些错误。 From various chatter it seems like there is already some production usage out of it, so I would suggest to give it a second look and of course communicate your concerns to us via从各种喋喋不休看来,似乎已经有一些生产用途了,所以我建议再看看它,当然,通过以下方式向我们传达您的担忧

http://forum.springsource.org/forumdisplay.php?42-Integration http://forum.springsource.org/forumdisplay.php?42-Integration
https://jira.springsource.org/browse/INT https://jira.springsource.org/browse/INT

Cheers Oleg干杯奥列格

Disclaimer: I am Spring Integration committer免责声明:我是 Spring Integration 提交者

One reason to use Camel over Spring Integration is when you need a more featureful EIP set.使用 Camel over Spring Integration 的一个原因是当您需要一个功能更强大的 EIP 集时。 Spring Integration doesn't provide abstractions over things such as ThreadPool. Spring Integration 不提供对诸如 ThreadPool 之类的东西的抽象。

Camel does provide additional constructs for this simplifying some of the aspects of working with concurrent code: Camel 确实为此提供了额外的构造,以简化处理并发代码的某些方面:

http://camel.apache.org/camel-23-threadpool-configuration.html http://camel.apache.org/camel-23-threadpool-configuration.html

If you have no need for this sort of thing and just want to connect file, JMS, FTP endpoints etc... then just use Spring Integration.如果您不需要这种东西,只想连接文件、JMS、FTP 端点等……那么只需使用 Spring Integration。

Camel 充当应用程序的中间件,可以在其中执行数据建模、消息值转换和消息编排。

如果您当前的应用程序在 Spring 中并且需要 EIP 的 Spring Integration 支持的功能,那么 Spring Integration 是最佳选择,否则需要更多第三方支持/协议/文件格式等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM