Represents The Camel Runtime System
Represents The Camel Runtime System
1. .process(Processor)
2. .bean()
3. seda
4. supported components
a. timer
b. direct
c. vm
5. supported processors
a. ChoiceProcessor
b. FilterProcessor
6.
Links
1. Enterprise Integration Patterns: http://camel.apache.org/enterprise-integration-
patterns.html
2. Tuts
http://www.mastertheintegration.com/camel/camel-introduction.html
3. http://camel.apache.org/bean-binding.html
CamelContext
A CamelContext object represents the Camel runtime system. You typically have one
CamelContext object in an application. A typical application executes the following steps:
Note that the CamelContext.start() operation does not block indefinitely. Rather, it starts
threads internal to each Component and Endpoint and then start() returns. Conversely,
CamelContext.stop() waits for all the threads internal to each Endpoint and Component to
terminate and then stop() returns.
CamelTemplate
The CamelTemplate class is a thin wrapper around the CamelContext class. It has methods that
send a Message or Exchange – both discussed in Section 4.6 ("Message and Exchange")) – to
an Endpoint – discussed in Section 4.1 ("Endpoint"). This provides a way to enter messages
into source endpoints,so that the messages will move along routes – discussed in Section 4.8
("Routes, RouteBuilders and Java DSL") – to destination endpoints.
Component
● Can better called as EndpointFactory as it is a factory for creating Endpoint instances.
● For example, if a Camel-based application uses several JMS queues then the
application will create one instance of the JmsComponent class (which implements the
Component interface), and then the application invokes CamelContext.getEndpoint();
internally, the CamelContext object finds the desired Component object (as I will discuss
shortly) and then invokes createEndpoint() on it.
● Another example:
myCamelContext.getEndpoint("pop3://[email protected]?password=m
yPassword");
The parameter to getEndpoint() is a URI. The URI prefix (that is, the part before ":")
specifies the name of a component. Internally, the CamelContext object maintains a
mapping from names of components to Component objects. For the URI given in the
above example, the CamelContext object would probably map the pop3 prefix to an
instance of the MailComponent class. Then the CamelContext object invokes
createEndpoint("pop3://[email protected]?password=myPassword") on
that MailComponent object. The createEndpoint() operation splits the URI into its
component parts and uses these parts to create and configure an Endpoint object.
Components list
1. http://camel.apache.org/timer.html
2. s
Component Types
1. SEDA components: https://camel.apache.org/seda.html
2. Direct compoenents: https://camel.apache.org/direct.html
3. VM components: https://camel.apache.org/vm.html
Endpoint vs Component
Parsing "jms:queue:order", Camel will use the "jms" scheme to lookup the
JmsComponent in the Component registry, which will create a JMS queue Endpoint
named "order". The Endpoint creates Producers and Consumers to handle the message.
Processor
The Processor interface represents a class that processes a message. The signature of this
interface is shown below.
Notice that the parameter to the process() method is an Exchange rather than a Message. This
provides flexibility. For example, an implementation of this method initially might call
exchange.getIn() to get the input message and process it. If an error occurs during processing
then the method can call exchange.setException().
An application-level developer might implement the Processor interface with a class that
executes some business logic.
Inbuilt Processors
● ChoiceProcessor: implements the message router pattern, that is, it uses a cascading if-
then-else statement to route a message from an input queue to one of several output
queues.
● FilterProcessor: discards messages that do not satisfy a stated predicate
Routes
A route is the step-by-step movement of a Message from an input queue, through arbitrary
types of decision making (such as filters and routers) to a destination queue (if any).
Two ways to specify routes.
● Using Xml
● Using Java DSL
Java DSL Example
RouteBuilder builder = new RouteBuilder() {
public void configure() {
from("queue:a").filter(header("foo").isEqualTo("bar")).to("queue:b");
from("queue:c").choice()
.when(header("foo").isEqualTo("bar")).to("queue:d")
.when(header("foo").isEqualTo("cheese")).to("queue:e")
.otherwise().to("queue:f");
}
};
CamelContext myCamelContext = new DefaultCamelContext();
myCamelContext.addRoutes(builder);
The first line in the above example creates an object which is an instance of an anonymous
subclass of RouteBuilder with the specified configure() method.