Camel is an open-source, Java-based project that helps the user to implement many of the design patterns in the Enterprise Integration Patterns book. When we talk about the the term endpoint, in client-server communication, the client is one end point and the server is another endpoint. An endpoint might refer to an address, such as a host:port pair for TCP-based communication, or it might refer to a software entity that is contactable at that address.
Some examples of the Camel-supported endpoint technologies are JMS queue, web service, file, FTP server, email address, POJO (plain old Java object).
In camel based applications, endpoints are created and connected with routes. Camel defines a Java interface called Endpoint. Each Camel-supported endpoint has a class that implements this Endpoint interface.
A CamelContext object represents the Camel runtime system. You typically have one CamelContext object in an application. After creating a CamelContext object, we can add end points and routes to connect the end points.
Invoking the start() operation on the CamelContext object, starts Camel-internal threads that are used to process the sending, receiving and processing of messages in the endpoints.Invoke the stop() operation on the CamelContext object stops all the endpoints and Camel-internal threads. CamelTemplate class is a thin wrapper around the CamelContext class. It has methods that send a Message or Exchange to an endpoint. Therefore, messages can be sent to source endpoints, messages will move along routers.
Components are used to create the endpoints. As an example, if we take JmsComponent class(implements Component), JmsComponent.createEndpoint() creates an instance of the JmsEndpoint class (which implements the Endpoint interface). In the application-level, CamelContext.getEndpoint() finds the desired Component object and then invokes createEndpoint() on it.
myCamelContext.getEndpoint("pop3://john.smith@mailserv.example.com?password=myPassword");
The parameter to getEndpoint is a URI. URI prefix(the part before :) is Component. CamelContext object maintains a mapping from names of components(pop3) to Component objects. CamelContext object invokes createEndpoint("pop3://john.smith@mailserv.example.com?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.
Message,Exchange and Processor
Message interface is an abstraction for a single message(request, reply or exception message). There are concrete classes that implement Message interface for each Camel supported communication technologies. The Exchange interface is an abstraction for an exchange of messages, that is, a request message and its corresponding reply or exception message. In Camel terminology, the request, reply and exception messages are called in, out and fault messages. There are also concrete classes that implement the Exchange interface for each Camel-supported communications technology.
The processor interface represents the process of a message. The classses that implement Processor interface provides support for a design pattern. For an example, ChoiceProcessor implements the message router pattern, FilterProcessor class which discards messages that do not satisfy a stated condition.
Routes, RouteBuilders and Java DSL
A route is the step-by-step movement of a Message from an input queue, through decision making (such as filters and routers) to a destination queue(if any). Camel provides two ways for an application developer to specify routes, XML file and Java DSL (domain-specific language). Java DSL is a class library that looks like DSL with JAVA
No comments:
Post a Comment