Passing values between processors in apache camel

前端 未结 4 996
太阳男子
太阳男子 2020-12-08 07:28

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
  • us
相关标签:
4条回答
  • 2020-12-08 07:54

    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

    0 讨论(0)
  • 2020-12-08 07:57

    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.

    0 讨论(0)
  • 2020-12-08 07:59

    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
    0 讨论(0)
  • 2020-12-08 08:14

    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.

    0 讨论(0)
提交回复
热议问题