A FUSE Mediation Router component consists of a set of classes that are related to each other
through a factory pattern. The primary entry point to a component is the
Component
object itself (an instance of
org.apache.camel.Component
type). You can use the Component
object as a factory to create Endpoint
objects, which in turn act as
factories for creating Consumer
, Producer
, and
Exchange
objects. These relationships are summarized in Figure 4.1
A component implementation is an endpoint factory. The main task of a component
implementor is to implement the Component.createEndpoint()
method, which is responsible for creating new endpoints on demand.
Each kind of component must be associated with a component
prefix that appears in an endpoint URI. For example, the file component is
usually associated with the file
prefix, which can be used in an endpoint URI
like file://tmp/messages/input
. When you install a new component in FUSE Mediation Router,
you must define the association between a particular component prefix and the name of
the class that implements the component.
Each endpoint instance encapsulates a particular endpoint URI. Every time FUSE Mediation Router encounters a new endpoint URI, it creates a new endpoint instance.
Endpoints must implement the org.apache.camel.Endpoint
interface. The Endpoint
interface defines the following
factory methods:
createConsumer()
and
createPollingConsumer()
—Creates a consumer endpoint,
which represents the source endpoint at the beginning of a route.
createProducer()
—Creates a producer endpoint,
which represents the target endpoint at the end of a route.
createExchange()
—Creates an exchange object,
which encapsulates the messages passed up and down the route.
An endpoint object is also a factory for creating consumer endpoints and producer endpoints.
Consumer endpoints consume requests. They always appear at the start of a route and they encapsulate the code responsible for receiving incoming requests and dispatching outgoing replies. From a service-oriented prospective a consumer represents a service.
Consumers must implement the
org.apache.camel.Consumer
interface. There are a number of
different patterns you can follow when implementing a consumer. These patterns are described in
Consumer Patterns and Threading.
Producer endpoints produce requests. They always appears at the end of a route and they encapsulate the code responsible for dispatching outgoing requests and receiving incoming replies. From a service-oriented prospective a producer represents a service consumer.
Producers must implement the
org.apache.camel.Producer
interface. You can optionally
implement the producer to support an asynchronous style of processing. See Asynchronous Processing for details.
Exchange objects encapsulate a related set of messages. For example, one kind of message exchange is a synchronous invocation, which consists of a request message and its related reply.
Exchanges must implement the
org.apache.camel.Exchange
interface. The default
implementation, DefaultExchange
, is sufficient for many
component implementations. However, if you want to associated extra data with the
exchanges or have the exchanges preform additional processing, it can be useful to
customize the exchange implementation.
There are three different kinds of messages:
In messages
Out messages
Fault messages
All of the message types are represented by the same Java object,
org.apache.camel.Message
. It is not always necessary to customize the
message implementation—the default implementation,
DefaultMessage
, is usually adequate.