IAmYourFaja
IAmYourFaja

Reputation: 56864

Apache Camel terminology subtleties

I'm trying to wrap my head around Apache Camel, and after spending some time this morning reading both the online Camel docs as well as the Javadocs, I have some questions that I can't seem to find answers for.

  1. Is it true that all endpoints are either consumers or producers (or both)? Is it true that all processors are endpoints? Are there any endpoints that are not processors?
  2. What's the difference between a Message header and an Exchange? An exchange is considered to be a "message container", but how is that different from the metadata that a header would contain?
  3. Is it typical to implement your own Message/Exchange? If so, what would be an example of doing so, and "straying" from the typical DefaultMessage and DefaultExchange?

Thanks in advance.

Upvotes: 2

Views: 306

Answers (2)

NitinS
NitinS

Reputation: 322

@DirtyMikeAndTheBoys you wrote:

Is it true that all processors are endpoints? Are there any endpoints that are not processors?

This is not true. 'Processors' in Camel terminology are callbacks which are part of some pattern (like Aggregator, Message Channel or RoutingSlip). Processors receive the messages when they are flowing within a route and do something on messages. Messages are wrapped within Exchanges.

An Endpoint is where a route will receive messages (consumer endpoint) and where it will send the processed messages (To endpoint). So when you see the 'from' clause in a route, Camel engine is using a 'Consumer' instance associated with the endpoint instance defined in 'from' clause. It really depends on the endpoint implementation whether a new consumer instance is created/reused every where that given endpoint appears in a 'from' clause in your camel context.

Similarly when the same endpoint is mentioned in a 'To' clause, a Producer instance will be used (either created/reused) and will remain associated with the endpoint instance.

Upvotes: 2

Petter Nordlander
Petter Nordlander

Reputation: 22279

First things first: A good suggestion is to read the book Camel in Action, it explains most of the basic concepts. There is a free first chapter available online which explains the kind of questions you ask http://manning.com/ibsen/

  1. An endpoint references a component and some component specific options, such as addresses etc. The endpoint can then (depending on the component) function as either consumer (ex. "servlet:path/to/web/service") or producer (ex. "http://localhost/path/to/web/service") or both of them (ex. "jms:queue:orderQueue").

  2. There are headers in Camel messages as well. An exchange outlives an entire route, and exchange properties will also stay for the entire route. Message headers in Camel are a bit different concept. They are often closely mapped to the component used - i.e. a HTTP endpoint might set/change headers (for instance COOKIES etc.) while HTTP headers has no influence on exchange properties as these are for use within the camel route and camel logic only. The exchange also wrapps other non message specific things, such as exceptions.

  3. It is quite uncommon to develop new message implementations. There could be a point in extending DefaultMessage when you have implemented your own component/protocol and need to keep instances of helper objects around in the message or whatnot. It's typically not done even when developing components. I have never heard of any custom implementation of an Exchange, and you should typically not do so without good reasons.

Upvotes: 2

Related Questions