Passing values between processors in apache camel

匆匆过客 提交于 2019-12-03 18:38:17

问题


In apache camel, which of those is the best way to pass values from an exchange processor to another (and why) :

  • storing it in the exchange headers
  • using the setProperty method while building the route.
  • another way..

回答1:


Properties and headers are pretty much the same. Headers are, however, converted to/from protocol specific headers on certain components, such as Jms. So,

  • Meta data inside a route: properties
  • Meta data to/from outside: headers



回答2:


One distinction not mentioned by Ben and Petter is that properties are safely stored for the entire duration of the processing of the message in Camel. In contrast, headers are part of the message protocol, and may not be propagated during routing. For example, JMS has limitations what you can store as headers etc.

You may want to read the free chapter 1 of the Camel in Action book as it covers the Camel concepts with Exchange, Message, etc.




回答3:


the Exchange is passed between Processors. It contains properties, IN message and optional OUT message. Each of these is capable of storing Object data, but in general:

  • use the Exchange Properties for general meta-data about the message (used less frequently)
  • use the IN message headers to configure endpoint properties or for meta-data about the message body (used often)
  • use the IN message body for the payload of the message (used most often)
  • create an OUT message only if necessary to maintain separate IN vs. OUT messages during processing (by default only IN is used)

That said, it really depends on the component called following your processor. Most have some headers and/or body values that are required to use the endpoint, etc. See the specific component page for these details.

Also, the Exchange/Message are explained in more detail on these pages:

http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html

http://fusesource.com/docs/router/2.8/prog_guide/MsgFormats-Exchanges.html




回答4:


Answer is here:

Properties: The properties is a Map and may look like message headers. The main difference is their lifetime: the properties exist during the whole exchange execution, whereas the headers are limited to the message duration (and a message can change a lot during routing, so during the exchange execution). Camel itself may add some properties for some use cases.



来源:https://stackoverflow.com/questions/10330998/passing-values-between-processors-in-apache-camel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!