You are on page 1of 11

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/262158670

Tutorial: open source enterprise application integration - introducing the event


processing capabilities of apache camel

Conference Paper · June 2013


DOI: 10.1145/2488222.2488269

CITATIONS READS

5 935

2 authors, including:

Florian Springer
Universität Regensburg
9 PUBLICATIONS   107 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Information Retrieval and Complex Event Processing View project

All content following this page was uploaded by Christoph Emmersberger on 15 May 2014.

The user has requested enhancement of the downloaded file.


Tutorial: Open Source Enterprise Application Integration
Introducing the Event Processing Capabilities of Apache Camel
Christoph Emmersberger Florian Springer
Universität Regensburg Senacor Technologies AG
Universitätsstraße 31 Wieseneckstr. 26
93053 Regensburg 90571 Schwaig b. Nürnberg
christoph@emmersberger.org florian.springer@senacor.com

ABSTRACT dleware.” ([3], 2) Middleware specifies a technology stack


“Interesting applications rarely live in isolation.” ([1], xxix) which is capable to mediate between applications with the
With this sentence G. Hohpe and B. Woolf start the intro- overall goal of improving the supply-chain relationships in a
duction to their book Enterprise Integration Pattern: De- distributed application environment. One of the frameworks
signing, Building, and Deploying Messaging Solutions. supporting the mediation between applications coming from
While the statement is valid now for more than ten years, the open-source domain is the integration framework Apache
Gartner estimates today the cost increase targeting integra- Camel. The first version of Camel has been released in ver-
tion aspects for midsize to large companies at about 33% sion 1.0 the 2nd July 2007 - just three and a half month
within the next three years (cf. [2]). The expected increase after the development had started (cf. [4]).
will be mainly driven by the integration of cloud services Regardless of the short development period, the first re-
and mobile devices. Since event processing addresses clearly lease covered already two domain specific languages (DSL’s)
problems arising with the growth of computational distri- based on Java and XML, the core routing functionality, an
bution, particularly with the increasing number of mobile initial set of components, examples and a proper project
devices or cloud services, integration is a topic that needs to setup [5]). Since than, Camel has become an Apache top
be addressed by event processing functionalities. level project in January 2009. Beside those organizational
One of the frameworks within the integration domain is changes, the project has faced continuous growth which can
Apache Camel. Since it’s initial release in 2007, the frame- be exemplified by
work has gained quite some attention - not only within the • the growing number of committers (starting at seven
open-source arena. Apache Camel has a strong focus on being a group of more than 30 today),
enterprise application integration since it implements well
• an increasing code base which is today more than ten
known Enterprise Integration Patterns (EIP’s) (cf. [1]).
times the size of the first release and
This work reveals the event processing capabilities of Apache
Camel alongside a logistics parcel delivery process. The de- • the growing number of components from an initial set
livery process facilitates the scenario descriptions to exem- of 18 to todays 140 components (including external
plify the event processing functionalities within a real-world components) listed at the Camel website (cf. [6]).
context. All coding examples, supporting the functionality
In August 2009, Camel has experienced a major release (cf.
demonstration, are setup around the shipment of parcels.
[7]). Since that time, it is available in version two which is
still actively maintained. Having said that Camel is a mid-
General Terms dleware technology and “(...) middleware can be regarded
Software Engineering as containing the roots of a hierarchical approach to events
and event processing (...)” ([8], 37), we can also identify a
clear relationship between enterprise application integration
Keywords and event processing.
Integration Framework, Event Processing Within this tutorial paper we introduce Apache Camel’s
event processing capabilities. The first section gives a brief
1. INTRODUCTION introduction into the context of a parcel delivery process.
“Enterprise Application Integration is the creation of busi- The process description does not claim to be generally valid;
ness solutions by combining applications using common mid- it’s aim is furthermore to serve as consistent basis for all use
case descriptions when characterizing the individual event
processing functions and their corresponding Camel imple-
mentation.
Permission to make digital or hard copies of all or part of this work for After having a rough overview about the supply-chain in-
personal or classroom use is granted without fee provided that copies are teractions, the second section brings event processing and
not made or distributed for profit or commercial advantage and that copies it’s functionalities into the focus of this work. In this con-
bear this notice and the full citation on the first page. To copy otherwise, to nection we’ll cover the the topic’s: “Event type and event
republish, to post on servers or to redistribute to lists, requires prior specific object”, “event producer, consumer and channel”, the “event
permission and/or a fee.
DEBS’13, June 29–July 3, 2013, Arlington, Texas, USA. processing network” and “event processing agents, context
Copyright 2013 ACM 978-1-4503-1758-0/13/06 ...$15.00. and state”.

259
The subsections event processing network, event producer, Delivery Disposition is the scheduling component within
consumer and channel and event type provide an introduc- the parcel delivery process. Amongst others, it defines
tion into the concepts of Apache Camel while creating cross the size of the delivery area and schedules transporta-
references to event processing building blocks ([9], 59). The tion routes. For distributing the scheduling informa-
section on event processing agents, context and state will be tion, the disposition step needs to integrate with the
covered in a software pattern like structure (cf. [1], xli and delivery execution, i.e. sorting sites, navigation sys-
[10], 7). Since it is unquestionable a topic of it’s own, set- tems and scan facilities.
ting a well defined structure for a pattern, we do not intend
to impose any standardization along that line. Instead the Delivery Execution realizes the actual transport process
pattern like descriptions collates the commonalities of both encompassing Pickup, Sortation, Transportation and
structures to describe event processing agent functionalities Delivery. At all stages, multiple devices with different
in a consistent manner. hard and software configurations provide status infor-
mation about an individual order, e.g. mobile scan de-
Name identifies the event processing function. The inten- vices during Pickup and Delivery, fixed installed scan
tion of the name is also to provide a brief summary of systems during the Sortation process and position-
the described functionality. ing information while the Transportation is being con-
Context provides background information on requirements ducted.
the event processing function aims to resolve. The con- Order Reconciliation covers the invoicing and customer
text information is grouped around the parcel delivery care activities. In case of any failures within the de-
process (cf. chapter 2) livery process, customers may receive a refund and
Problem summarizes the problem that is being addressed an insurance claim needs to be opened. Otherwise a
by the event processing function in general without monthly bill is created and the incoming payments will
any contextual description. be monitored against payment transactions.

Solution describes how Camel addresses the problem con-


ceptually. The solution is based upon a graphical rep-
3. EVENT PROCESSING
resentation and a textual description that explaining Middleware is, beside other technologies, one of the estab-
the solution design. lished technology stacks which has clearly adopted the event
processing paradigm ([8], 27-29 and 36-38). This section dis-
Example demonstrates the implementation of the solution covers Camel’s implementation of the main event processing
design with the Apache Camel framework. The de- concepts ([9], 40-47) starting with event types and objects,
scription contains listings and descriptive elements that highlighting the event producer, consumer and channel con-
explain the implementation approach. cept, integrating the components into an event processing
Finally this paper concludes in chapter 4 with a summary network and finally discussing the interaction of event pro-
of Camel’s event processing capabilities and discusses pos- cessing agents, context and state.
sible extensions supporting today’s event processing needs.
Event types and event objects Events are a represen-
tation for something which has happened. As a com-
2. BACKGROUND: PARCEL DELIVERY putational element for the technical representation, an
A common parcel logistics delivery process (cf. [11], 171), event object is a concrete instance of an event type. All
starting with a customer order and ending with reconcili- event objects, which belong to an event type, carry the
ation and invoicing activities, serves as industrial context same semantics within their object structure. Event
on which we will discover different event processing func- types, objects and their implementation within Camel
tionalities and their corresponding implementation within are covered in section 3.1.
Camel. The generalized process consists of Order Manage-
ment, Delivery Disposition, Delivery Execution and Order Event producer, consumer and channel Producer and
Reconciliation (see figure 1). consumer are both event processing elements that com-
municate with each other. While an event producer
obtains the role for generating events, the event con-
sumer receives the results. An event channel fulfills the
Order Delivery Delivery Order
Mgmt. Disposition Execution Reconc. mediation role between producer and consumer. It’s
main task is to route events from the producer to the
appropriate consumer. All three elements and their
technical interaction are described in section 3.2.
Figure 1: Parcel Delivery Process
Event processing networks An event processing network
combines all processing elements, notably event pro-
Order Management enables the placement of transporta- ducer and consumer, event channel, event processing
tion orders across multiple distribution channels. The agent including context and state elements into an ex-
distribution channel is e.g. an internet portal, an appli- ecutable application unit. This does not necessarily
cation installed at the customer location, a call center imply that all elements need to be executed within a
or even a mobile application. An electronic order trig- single execution node. In section 3.3 you’ll find an
gers the physical pickup of an item before the delivery in depth explanation on how the combination can be
execution can start. achieved within Camel.

260
Event processing agents, context and state An agent (cf. [13], 14). It is therefore possible to process any event
is a software component with the purpose of process- that can be serialized into a Java object.
ing events. The main functionalities of an agent can be
summarized as filtering, matching and derivation with
Listing 2: Event Object - Shipment Order
support of context and state information. While filter- 1 <?xml v e r s i o n=” 1 . 0 ” e n c o d i n g=”UTF−8”?>
ing, matching and derivation are core functions within 2<t n s : Shipment ... >
event processing, the processing of context and state is 3 <t n s : S h i p m e n t D e t a i l s >
required for event reasoning which means the detection 4 <t n s : ParcelType>
of any conditions that lead to the event generation (cf. 5 Small P a r c e l
section 3.4) 6 </ t n s : ParcelType>
7 <t n s : Weight >1.87</ t n s : Weight>
8 <t n s : Length >55</ t n s : Length>
3.1 Event Types and Event Objects 9 <t n s : Width>25</ t n s : Width>
An event is a representation for something which has hap- 10 <t n s : Height >12.5</ t n s : Height>
11 </ t n s : S h i p m e n t D e t a i l s >
pened in reality (cf. [12], 151 and [8], 255-256 and [9], 4).
12 <t n s : S en d er . . . />
Considering the parcel delivery process of figure 1, the cen- 13 <t n s : R e c e i v e r . . . />
tral event which triggers all subsequent activities is a cus- 14 </ t n s : Shipment>
tomer order for the transportation service, also known as
Shipment. While the actual instance of an event is called Having introduced the abstract relationship between event
event object, the structural definition is captured within an type and event object, we need to investigate the logical
event type. structure of an event and it’s attributes. Since the XML-
Listing 1 and 2 disclose the relationship between event type based example above represents only the payload, which is
and event object. The event type in listing 1 defines, that usually wrapped in the event body within the context of
a shipment order consists of ShipmentDetails, Sender and event processing, we need to discover what other attributes
Receiver. ShipmentDetails describes the nature of the Ship- are required to create an event. In addition we need to find
ment, particularly the size and weight of the item; Sender out, if these elements find an implementation representation
and Receiver specify the geographical nodes and the distance within the Camel framework.
that needs to be covered by the Shipment. According to ([9], 62-64), the abstract, logical structure
of an event is split into three sections: An event header, a
payload and an open content section. The following enu-
Listing 1: Event Type - Shipment Order meration describes each element and it’s role within event
1 <?xml v e r s i o n=” 1 . 0 ”?> processing.
2<xsd : schema v e r s i o n=” 1 . 0 ” . . . >
3 <xsd : e l e m e n t name=”Shipment ”
4 t y p e=” t n s : ShipmentType ”/>
Header: Covers system defined event attributes e.g. a type
5 <xsd : complexType name=”ShipmentType ”> identifier, a property that flags if it is an event com-
6 <xsd : s e q u e n c e > position, the temporal granularity and additional event
7 <xsd : e l e m e n t name=” S h i p m e n t D e t a i l s ” indicators such as the occurrence and detection time,
8 t y p e=” t n s : S h i p m e n t D e t a i l s T y p e ”/> event source, identity and certainty. Header attributes
9 <xsd : e l e m e n t name=”Sender ” support an efficient processing of the events since they
10 t y p e=” t n s : SenderType ”/>
11 <xsd : e l e m e n t name=” R e c e i v e r ”
reduce the need to lookup frequently used information.
12 t y p e=” t n s : R e c e i v e r T y p e ”/>
13 </xsd : s e q u e n c e >
Payload: Contains data attributes that are specified by the
14 </xsd : complexType> event type. The payload data is the actual, computa-
15 ... tional representation of what has happened (cf. listing
16 </xsd : schema> 1 and 2).
In contrast to the event type, which describes the seman- Open content: Defines additional data that may be in-
tical structure of an event, the event object captures what cluded in the even instance. This encompasses any bi-
is actual happening or has happened - in our example the nary attachment such as any document, audio or video
concrete request of an order. The event object is therefore file. However, it is also possible to attach structure or
an instance of an event type which contains actual values un structured text.
within the structure of the event type. Listing 2 shows an in-
stance of the Shipment with concrete values. While Weight, The logical event structure has its representation within
Length, Width and Height define the physical consistency Camel as message object, consisting of headers, a body and
of the Shipment, the ParcelType provides a classification in- an attachment (cf. [13], 13). When taking a look at the
formation, in our case “Small Parcel”. This classification headers object, we can identify a unique messageId. In spite
information is not necessarily required, since it could be de- of the messageId there exist no other predefined message
rived by some context information, e.g. when conducting a headers and it is necessary to extend the research also to
lookup against a context store. For the purpose of simplicity the surroundings of the message object to find additional in-
we decided to retain the attribute and discuss the topic of formation like the ones defined by the event indicators, e.g
context in section 3.4. the event source.
Adding one more comment to the given XML listing: It In figure 2 we find an abstract illustration that explains how
is of course not an imperative need to specify an event body the message object is embedded within the broader context
as XML structure. Camel supports any Java object type in of an exchange object. An exchange may contain two mes-
its message body since the body is of type “java.lang.object” sage objects, an in and an out object. The reason for that

261
implementation can be found within the concept of message upon the scheduling request and enables the order system
exchange pattern (MEP). Camel knows basically two styles to send out an order confirmation to the customer’s inbox
of exchanging messages: InOnly and InOut ([13], 14-15) . in the portal application.
While some interaction scenarios manage the processing of
a “fire and forget” style (i.e. InOnly pattern), others require
1 2
still the information about the original request message (i.e.
<< sendOrder() >> << requestScheduling() >>
InOut pattern). To implement this behavior, the exchange
contains the information about the pattern style and the op- Customer Order Scheduling
tion to store two messages. Portal System System
In addition of the processing behavior, the exchange has
also an attribute indicating the endpoint where the message << confirmOrder() >> << replySchedule() >>
camel from respectively the event source (cf. section 3.2). 4 3
Beyond that, the concept involves also the knowledge about
it’s creation time (i.e. properties.CamelCreatedTimestamp),
the execution context (i.e. fromRouteId ) as well as the infor- Figure 3: Order Submission
mation if any processing failure. The advantage of carrying
exception information outside of the actual message is, that Under the condition of each participant acting either as
the the exception handling needs only to look at this infor- producer or consumer, the example (cf. figure 3) demon-
mation rather than parsing the entire message body. strates that each participant can obtain multiple roles de-
If it is required to add any additional event indicators, this pending upon the communication direction. At first, when
can be handled by setting custom properties within the mes- sending the order request, the customer portal holds the
sage header or the exchange properties. event producer role before it turns into an event consumer
when finally receiving the order confirmation. Since the role
change does not affect any internal semantics or structure
Message
of data within the customer portal, it is possible to combine
both roles into a single element, called participant (cf. [9],
0..1 0..1 33 and [14], 298). The Camel implementation of a partici-
-out -in pant element is realized via the so called Component object
(cf. [13], 188-236).
“Components are the primary extension point in Camel”
Endpoint Exchange ([13], 189) and implement basically an endpoint factory.
0..1
Since any endpoint is capable to send and receive events,
-fromEndpoint
a component exposing an endpoint is suitable to realize an
-pattern event producer as well as a consumer. What might become
0..1 a surprise is, that the generic Component concept is also
Exchange capable to realize the concept of an event channel. First of
Pattern all, an event channel is capable to receive events, similar to
the behavior of an event consumer. Secondly, it acts like an
event producer when sending events to one or more destina-
tions. Finally, an event channel may also modify an input
Figure 2: Camel Exchange and Message Model event or make routing decisions (cf. [9], 189).
Since a Camel Component provides basically a configurable
Reviewing the overall Camel implementation it is fair say, endpoint to which someone can send events or may retrieve
that the message and exchange concept provides everything events, it is possible to cover the first and second state-
which required by an event type and object perspective to ment. In addition the endpoint configuration may also con-
fulfill the needs required for event processing. tain information on how to modify (e.g. change header in-
The next section introduces now the concepts of event formation) or apply routing decisions. Figure 4 provides an
producer, consumer, event channel and tries to discover their overview about the object dependencies in Camel between,
implementation within the Camel framework. producer, consumer, component and endpoint.

3.2 Event Producer, Consumer and Channel Component is a factory for endpoint objects. Components
can be added to an EPN via configuration and inclu-
Event producer and consumer are entities that interact sion to the Camel Context (cf. section 3.3).
with each other in an event processing network (cf. sec-
tion 3.3) by sending and receiving events (cf. [9], 42). Taking Endpoint realizes an addressable element that can send
an example from the parcel delivery process (cf. figure 1), a and receive event objects. The endpoint address is
customer may submit a shipment order in a customer por- specified as Unified Resource Identifier (URI) (cf. [15]).
tal. The order is being sent to the order system which keeps
Producer provides a channel on which clients can send
track about the fulfillment degree of all customer orders (cf.
event objects in an endpoint. The endpoint needs to
figure 3). Before the order system is in capable to confirm
be individually configured.
that the order can be processed, it requires additional in-
formation about the feasibility from the scheduling system Consumer consumes events from an endpoint. Consuming
since the order system does not know anything about capac- events requires an individual configuration, including
ities and their utilization. The scheduling system responds the appropriate endpoint addressing.

262
ing context unique. This is required to address the
Component individual component instance when calling an end-
point.
0..1
- component Options: Options configure the endpoint behavior. The
set of options is different for each component since
Endpoint the behavior depends upon the underlying component
provider (e.g. the scheduling system)
0..1 0..1
- endpoint - endpoint
Having seen now, how Camel realizes event types and
Producer Consumer event objects (3.1), and knowing how event producer, con-
sumer and channel (3.2) are implemented and interact within
the framework, it is time to discover the complete interac-
tion of all elements within the event processing network.
Figure 4: Abstract Component Model 3.3 Event Processing Networks
“An event processing network (EPN) is a collection of
Having gained a first insight into the component concept event processing agents, producers, consumers, and global
and its adoption to realize event producer, consumer and state elements (...)” (cf. [9], 43). As we have seen in 3.2,
channel we’d like to give you an example that should pro- most of the elements can be express via components. To
vide some clarification. As example, we have selected two combine these components, Camel provides two essential el-
implementations within Camel that act like event channels, ements called context and route.
since a channel realizes both communication directions.
The first component is called SEDA-component and realizes Context: The Camel Context is a container at runtime
the concept of a staged event-driven architecture endpoint level, providing Camel’s core services, particularly the
(cf. [16]). This endpoint implements in our example (cf. elements Registry, Type converter, Components, End-
listing 3) an endpoint that can receive events. Nevertheless, points, Routes, Data formats and Languages (cf. [13],
a SEDA endpoint may be also used to send events; it can 16).
therefore act in both consumer and producer role. In ad-
Route: A Camel Route realizes a concrete implementation
dition, the component has also the capability to configure
of a message flow that can be executed on Camel’s
basic routing rules such as the enablement of multiple con-
routing engine. It is possible to define multiple routes
sumers, similar to a topic based communication, as well as
within a context, where each contains a unique identi-
some blocking and sizing parameters.
fier (cf. [13], 17).
The second component we have decided to use as an event
channel is the JMS-component, since the Java Message Sys- To get an impression on how a Camel Context and Camel
tem (JMS) ([17]). is a well known implementation of the Routes are structured, we have created a simple listing 4
event channel concept. that provides some clarification. The listing is based upon
Listing 3 shows the mediation between two systems. The the Spring DSL (cf. [13], 18) and is embedded in a Spring
first system, in our case the order system, is capable to call application context (cf. [18], 27). A context element, named
a SEDA queue directly while the second system, responsi- “camelContext” contains a single route with a unique iden-
ble for scheduling and routing, can only understand JMS tifier “camelRoute”; in addition to that single route it would
messages (cf. figure 3). The communication direction, re- be possible to add more routes within that context where
spectively the indication of which component acts as event all can access the same set of core services provided by the
producer or consumer, is described by the Camel DSL, a context. Two core services that must to be registered in our
processing language with simple routing expressions. In our example are the SEDA and JMS component, since they are
example it is a simple “from().to()” clause based upon the directly referenced from the route and will be instantiated.
fluent builder concept (cf. [13], 30, 132). Another one is of course the registry that administers all
context paths for all endpoints to enable a proper endpint
Listing 3: Endpoint URI Examples resolution when processing the messages.
1 from ( ”s e d a : / / shipmentOrder ” +
2 ”? m u l t i p l e C o n s u m e r s=f a l s e ” )
3 . t o ( ”jms : t o p i c : s c h e d u l e ? t r a n s a c t e d=t r u e ” ) ; Listing 4: Context and Route - Application Context
1 <?xml v e r s i o n=” 1 . 0 ” e n c o d i n g=”UTF−8”?>
As already stated, a component can be addressed via an 2<beans xmlns : camel=

URI scheme. In contrast to the URI specification (cf. [15], 3 ”h t t p : / / camel . apache . o r g / schema / s p r i n g ”
16-25), Camel implements a simplified URI structure (cf. 4 x s i : s c h e m a L o c a t i o n=
5 ”h t t p : / / camel . apache . o r g / schema / s p r i n g
[13], 19, 25) to configure and address an endpoint individu-
6 h t t p : / / camel . apache . o r g / schema / s p r i n g /
ally (cf. listing 3). A Camel endpoint URI is based upon a camel−s p r i n g . xsd ” . . . >
scheme, a context path and options. 7 <camel : camelContext i d=”camelContext ”>
8 <camel : r o u t e i d=”camelRoute ”>
Scheme: The scheme references the component that needs 9 <camel : from u r i=”s e d a : / / shipmentOrder ”/>
to be instantiated. The component identifier needs to 10 <camel : t o u r i=
be uniquely. 11 ”jms : t o p i c : s c h e d u l e ? t r a n s a c t e d=t r u e ”/>
12 </camel : r o u t e >
Context path: Identifies the resources within the process- 13 ...

263
14 </camel : camelContext> data that needs to be distributed to the subsequent delivery
15 </beans> nodes.
Problem: Since subsequent processing nodes are only
As we have seen in the example of listing 4, Camel Context interested in events for their delivery area, it is required to
and Camel Routes enable the collection of components (e.g. select the particular parcel information and distribute it to
event producer, consumer and channel ). We might want to the corresponding node. However each node needs the flex-
anticipate the result of section 3.4 to conclude that it is also ibility to change the size of the delivery area, since it must
possible to collect agents, context and state elements within be capable to take over the operation of a nearby delivery
the concept. area, in case of e.g. low volumes or operational issues in a
The following section explains the concept of agents, con- processing node.
text and state in detail and points out concrete implemen- Solution: Providing the flexibility to dynamically change
tation strategies for each agent functionality. the area, all address events will be published on a single
topic. Each node within the delivery network is responsible
3.4 Agents, Context and State to create a filter expression matching the predefined delivery
An event processing agent is a piece of software that im- area. This way it can be assured that each node receives only
plements the processing logic between an event producer and events for it’s field of activity.
a consumer (cf. [9], 42, 51). Each agent provides a specific
set of event processing functionality that can be assembled
within an event processing network. The main tasks of an
agent are therefore the mediation between producer and con-
sumer, particularly the grouping of events according to their
processing context. This can be achieved e.g. by filter, split,
Messages Filter Messages
translate, aggregate and enrich functionalities.
In addition to these functions, agents are also responsible
to process context and state information which enables also
the correct routing from the event producing to the event Figure 5: Filter Agent
consuming component (cf. [9], 51, 145). The context of an
Example: In the example we are sending address events
event may have multiple dimensions, e.g. temporal-, spatial-
captured by the sorting machine that contain name, street,
, or state-oriented, where each context dimension can occur
city and zipCode information. For the purpose of simplicity,
in combination with each other one. Identifying the right
we assume that a zipCode identifies a section of a deliv-
context for an event can only be conducted, if there is a
ery area and can not be split into the responsibility of two
global state element available acting as reference data.
processing nodes. An active delivery node can serve one to
Agent functionality can be reused in different application
many zipCode areas at once while an inactive node main-
scenarios. To support the reuse, we have proposed a simpli-
tains zero. As an additional restriction we have defined that
fied pattern schema (cf. section 1) containing name, context,
a processing node can only serve a coherent, ascending se-
problem, solution and example descriptions.
quence of zipCodes. All these restrictions have certainly not
Even if our intention is not to set a standard, the proposed
a direct, representation in the real parcel delivery process.
structure may contribute to the ongoing discussion about
However they help us to realize a simple filter expression as
standardization within the event processing community (cf.
you can see in the in listing 5 by a predicate.
[19]). One of the positive effects a pattern based approach
The predicate evaluates all incoming events for a minZip-
might have is that “[c]learly-defined and commonly-accepted
Code and a maxZipCode and routes all events within that
levels of abstraction enable the development of standardized
range to the responsible processing node. Camel executes
tasks and interfaces.” ([20], 48).
the filtering request within the route by calling the filter()
The subsequent paragraphs focus on the agent functional-
expression with a predicate parameter.
ity description for filtering, splitting, translation, aggregation
and enrichment based on the logistics parcel delivery pro-
cess (cf. figure 1). Even if the industrial background is taken Listing 5: Filter Agent
from logistics, we have kept the examples general to enable 1 public c l a s s FilterRoute extends
the adoption towards other industry domains. 2 SpringRouteBuilder {
3 @Override
4 p u b l i c v o i d c o n f i g u r e ( ) throws E x c e p t i o n {
3.4.1 Filter Agent Pattern 5 Predicate deliveryArea =
“A [f]ilter agent (...) performs filtering only and has no 6 or (
7 body ( ) . i s G r e a t e r T h a n ( minZipCode ) ,
matching or derivation steps (...)” ([9], 317). To eliminate
8 body ( ) . i s L e s s T h a n ( maxZipCode ) ) ;
uninteresting events it utilizes a filter expression. The agent 9 from ( ” d i r e c t : / / s t a r t −body− f i l t e r ” )
processes events in a stateless manner (cf. [9], 51) 10 . f i l t e r ( deliveryArea )
Name: Filter Agent 11 . t o ( ” l o g : / / a f t e r −body− f i l t e r ? l e v e l=INFO” )
Context: The logistics of parcel delivery is characterized 12 . end ( ) ;
by automated sorting processes. Sorting machines pickup 13 }
14 }
the labeling information required for routing parcels phys-
ically to their corresponding gates . While the parcels are
being processed on conveyor belts, the capturing of the la- 3.4.2 Split Agent Pattern
bel information is being conducted based on barcode scans A split agent “(...) takes a single incoming event and emits
or image recognition. It extracts a huge amount of address a stream of multiple event objects ()” ([9], 52). It can be used

264
to partition an incoming event and distribute the individual from the customer portal provider stateing that there is a
parts to different consumers (cf. [9], 126). Java interface where product data can be updated.
Name: Split Agent Problem: Unfortunately the Java interface can not seri-
Context: Several customers are having distributed pro- alize XML documents directly and it provides only a remote
duction facilities while maintaining a single administration method invocation interface. The interface is therefore only
office that sends out the collected order requests for the en- capable to directly process Java objects. What makes the
tire customer organization. The centralized, batch oriented situation even more complicated is, that some of the ex-
order processing provides the customer the opportunity to tracted attributes do not match to the data structure spec-
centralize the purchase and accounting department at a sin- ified within the interface documentation.
gle location rather than having multiple employees sitting in Solution: The only way to support the marketing and
each production facility. sales department in their goal to update the companies por-
Problem: Distributing the bulk of orders is difficult, tal automatically based on the extracted XML data is to
since the pickup of parcels at the customer’s production fa- translate the XML product data into the format required
cilities needs to be executed by different logistics processing by the portal software. It is therefore required to translate,
nodes. Assigning the individual responsibility for the pro- the XML InputStream into an object of Product.class.
cessing nodes is not possible based on the entire set of order
events.

Initial Message Enriched


Message Translator Message

Message Splitter Messages Figure 7: Translate Agent

Example: The XML document that can be extracted


Figure 6: Split Agent from the spreadsheet has a product container with the at-
tributes name, size, weight and a price (cf. listing 7). Since
Solution: To enable the responsibility assignment across the specified Product.class object has only a description el-
the logistics network it is required to partition the order ement and no size and weight attributes, it is required to
collection into single orders where each order contains only translate these attributes into a single element.
the address information of the parcel’s sender and recipient.
This can be achieved by conducting a split operation on the Listing 7: Extracted XML-based Product
incoming collection. 1 <?xml v e r s i o n=” 1 . 0 ” e n c o d i n g=”UTF−8”?>
Example: The solution can be achieved by splitting the 2<Product>
3 <Name>P a r c e l </Name>
incoming order collection into it’s individual parts. Camel
4 <S i z e >max . 60 x30x15 cm</S i z e >
provides the split() expression for conducting those opera- 5 <Weight>up t o 2 kg</Weight>
tions. One of the requirements to implement the split ex- 6 <P r i c e >4.90</ P r i c e >
pression successfully is to have either a Collection, an Array 7 </Product>
or a NodeList (cf. [21], 23-24).
The proposed implementation for that translation is a
TypeConverter (cf. [13], 88-91). Since the default set of
Listing 6: Split Agent TypeConverter does not cover the specific translation be-
1 public c l a s s SplitRoute tween the XML-based product document and the Java-based
2 extends SpringRouteBuilder {
3 @Override
Product.class, it is necessary to extend the existing set by a
4 public void c o n f i g u r e ( ) { custom converter (cf. listing 8).
5 from ( ” d i r e c t : / / s t a r t − s p l i t ” )
6 . s p l i t ( body ( ) )
7 . t o ( ” l o g : / / s p l i t −r o u t e ? l e v e l=INFO” ) ; Listing 8: Translate Agent - Type Converter
8 } 1 @Converter
2 public c l a s s TranslateConverter {
9}
3 @Converter
4 p u b l i c Product c o n v e r t I n p u t S t r e a m T o P r o d u c t (
3.4.3 Translate Agent Pattern 5 InputStream i n p u t S t r e a m ) {
6 f i n a l XPath xPath = XPathFactory .
A translate agent is stateless and “(...) takes a single event 7 n e w I n s t a n c e ( ) . newXPath ( ) ;
as its input, and generates a single derived event which is 8 f i n a l Document document =
a function of the input event, using a derivation formula” 9 createXMLDocument ( i n p u t S t r e a m ) ;
([9], 125). Its usage ranges from simple type conversions to 10 r e t u r n c r e a t e P r o d u c t ( document ) ;
complex event transformations modifying event attributes. 11 }
Name: Translate Agent 12 p r i v a t e Product
13 c r e a t e P r o d u c t ( Document document ) { /∗ . . . ∗/
Context: The marketing and sales department has fig- 14 return product ;
ured a way, to extract product data as XML documents from 15 }
their master spreadsheet where they maintain all product in- 16 p r i v a t e Document createXMLDocument (
formation. They have also found a documentation section 17 InputStream i n p u t S t r e a m ) { /∗ . . . ∗/

265
18 return null ; aggregation strategy. The strategy has as a public aggre-
19 } gate() function which takes an old and a new exchange ob-
20 } ject as parameter values. While the old exchange contains
To trigger the translation, it is necessary to add a convert- all events that have been collected until the completion cri-
BodyTo(Product.class) expression to your route. At execu- teria is met, the new exchange involves the latest event ob-
tion time, the route identifies the object type that reaches ject. Based on these event objects, it is possible to calculate
at the conversion point and searches for a matching type an average product price and return the calculated value as
converter in the Camel Context registry. exchange object.
When the type conversion succeeds, the translate agent sends
out the Product.class object by executing a remote method Listing 10: Aggregate Agent - Aggregation Strategy
invocation (cf. listing 9) 1 p u b lic c l a s s Aggregator
2 implements A g g r e g a t i o n S t r a t e g y {
3 p r i v a t e f i n a l s t a t i c L i s t <Product> PRODUCTS =
Listing 9: Translate Agent - Route 4 new A r r a y L i s t <Product >() ;
1 public c l a s s TranslateRoute
5 p u b l i c Exchange a g g r e g a t e (
2 extends SpringRouteBuilder {
6 Exchange oldExchange ,
3 @Override
7 Exchange newExchange ) {
4 public void c o n f i g u r e ( ) {
8 f i n a l Product o l d P r o d u c t =
5 from ( ” d i r e c t : / / s t a r t −t r a n s l a t e ” )
9 getProductFromExchange ( oldExchange ) ;
6 . convertBodyTo ( Product . c l a s s )
10 f i n a l Product newProduct =
7 . t o ( ”rmi : / / p o r t a l : 1 0 9 9 / p r o d u c t s ” ) ;
11 getProductFromExchange ( newExchange ) ;
8 }
12 i f ( n u l l != newAggregateProduct ) {
9}
13 i f ( !PRODUCTS. c o n t a i n s (
14 newAggregateProduct ) ) {
3.4.4 Aggregate Agent Pattern 15 PRODUCTS. add ( newAggregateProduct ) ;
16 }
An aggregate agent “(...) takes as input a collection of 17 }
events and creates a single derived event (...)” ([9], 126). 18 newExchange . g e t I n ( ) . setBody (
Even if this definition describes the input as collection of 19 calcAvgProductPrice () ) ;
events it is not within the meaning of a Javacollection type 20 r e t u r n newExchange ;
where a collection represents a container object that em- 21 }
braces multiple objects. We want to emphasize that the 22 p r i v a t e Product getProductFromExchange (
23 Exchange exchange ) { /∗ . . . ∗/
aggregate agent operates on multiple input events and gen- 24 return product ;
erates a single output event. 25 }
When aggregating events, it is sometimes required to exe- 26 p r i v a t e double calcAvgProductPrice ( ) {
cute an aggregation function such as calculating e.g. a sum, 27 /∗ . . . ∗/
an average or the maximum and minimum of a certain event 28 return ProductPrice ;
attribute. 29 }
30 }
Name: Aggregate Agent
Context: Since the competition within the parcel de- Beside the actual calculation logic and the call of the ag-
livery market has increased and the prices became more gregation strategy (aggregate()), the definition of the com-
volatile, the marketing and sales department wants to gain pletion criteria is the most important element that needs
an insight into the average price for products and services to be defined. The criteria defines either the size (com-
offered by their competitors. pletionSize()) or the time frame (completionInterval() and
Problem: Calculating the average market price requires completionTimeout()) that triggers the execution of the ag-
the aggregation of all competitors prices. As soon as one of gregation strategy. To assure that the average price is being
the competitors changes the price, it is necessary to recal- calculated for every new product event, we have decided set
culate the average value. the completionSize to one (cf. listing 11).
Solution: To enable the reaction upon any price change,
the proposed solution is to aggregate a new average price as
soon as one of the competitors updates it’s price table. The Listing 11: Aggregate - Agent Route
aggregation will be implemented via an aggregation strategy 1 p u b l i c c l a s s AggregateRoute
2 extends SpringRouteBuilder {
hiding the complexity of calculating the average value. 3 @Override
4 public void c o n f i g u r e ( ) {
5 f i n a l Aggregator aggregator =
6 new A g g r e g a t o r ( ) ;
7 from ( ” d i r e c t : / / s t a r t −a g g r e g a t e ” )
8 . a g g r e g a t e ( body ( ) , a g g r e g a t o r )
9 . completionSize (1)
10 . t o ( ” l o g : / / a g g r e g a t e −r o u t e ? l e v e l=INFO” ) ;
11 }
Messages Aggregator Message
12 }

Figure 8: Aggregate Agent 3.4.5 Enrich Agent Pattern


An enrich agent “(...) takes a single input event, uses it to
Example: Listing 10 shows the implementation of a Camel query data from a global state element, and creates a derived

266
event which includes the attributes from the original event, Listing 13: Enrich Agent - Route
possibly with modified values, and can include additional 1 p u b l i c c l a s s EnrichRoute
attributes.” ([9], 126). 2 extends SpringRouteBuilder {
3 @Override
Name: Enrich Agent
4 public void c o n f i g u r e ( ) {
Context: A customer places an order by providing with 5 configureMainRoute ( ) ;
the physical characteristics and the distance information de- 6 configureEnrichRoute () ;
rived by the points of transfer (e.g. sender and receiver). In 7 }
contrast to the described order event of section 3.1, he does 8 p r i v a t e void configureMainRoute ( ) {
not offer any product classification that can be consulted for 9 from ( ” d i r e c t : / / s t a r t −e n r i c h ” )
10 . e n r i c h ( ” d i r e c t : / / s t a r t −e n r i c h m e n t ” ,
payoff. 11 new E n r i c h e r ( ) )
Problem: To create an accurate bill, it is required to 12 . t o ( ” l o g : / / e n r i c h −r o u t e ? l e v e l=INFO” ) ;
classify the order into the appropriate product category, e.g 13 }
small parcel, parcel or oversized parcel, each having an indi- 14 p riv ate void configureEnrichRoute ( ) {
vidual price tag. 15 from ( ” d i r e c t : / / s t a r t −e n r i c h m e n t ” )
Solution: To conduct the mapping of the provided in- 16 . process (
17 new P r o c e s s o r ( ) {
formation, it is required to lookup the event context in the 18 public void process (
global state element. This can be achieved by implementing 19 Exchange exchange ) { /∗ . . . ∗/
the enrichment pattern that implies in the concrete instance 20 exchange . g e t I n ( ) . setBody ( c o n t e x t ) ;
the querying of the product database based on the assigned 21 }
order event to return the corresponding product category. 22 }
23 )
24 . t o ( ” l o g : / / enrichment−r o u t e ? l e v e l=INFO” ) ;
25 }
Enricher
26 }

Initial Enriched
4. CONCLUSION
Message Message Within this work we have demonstrated, that Camel as an
integration framework clearly realizes event processing con-
cepts. It provides all the basic requirements needed for event
Resource
types and objects while maintaining an extension mechanism
to add additional, upcoming features targeting their struc-
tural semantics (cf. section 3.1).
Figure 9: Enrich Agent What might be a surprise is, that Camel’s generic compo-
nent concept can serve as an abstraction for event producer,
Example: The implementation is realized by adopting consumer and channel (cf. section 3.2). Nevertheless, it has
the aggregation strategy since an aggregation strategy is ca- been proven that the concept is sound since its adoption can
pable calculating a new output event based on two input be exemplified with the number of 140 realizing components,
exchanges (cf. listing 12). all acting either as event producer, consumer or implement-
ing a channel. The introduction to the interaction of event
processing networks by realizing Camel context and Camel
Listing 12: Enrich Agent - Aggregation Strategy route completes the frameworks support for the event pro-
1 p u b l i c c l a s s E n r i c h e r implements cessing building blocks.
2 AggregationStrategy { Finally the paper contributes towards the ongoing standard-
3 p u b l i c Exchange a g g r e g a t e ( ization effort by introducing the agent functionalities for
4 Exchange oldExchange ,
5 Exchange newExchange ) { filtering, splitting, translation, aggregation and enrichment
6 f i n a l Context o r i g i n a l C o n t e x t = (cf. section 3.4).
7 oldExchange . g e t I n ( ) . getBody ( Since we have seen, that Camel provides such a variety of
8 Context . c l a s s ) ; functions and knowing that it is a lightweight framework, it
9 f i n a l L i s t <Context> c o n t e x t = might be a good candidate to be used for assembling services
10 newExchange . g e t I n ( ) . getBody ( L i s t . c l a s s ) ; within a data cloud. An indication supporting this observa-
11 /∗ . . . ∗/
12 oldExchange . g e t I n ( ) . tion is, that Camel provides already many components that
13 setBody ( o r i g i n a l C o n t e x t ) ; support the integration of modern technologies and services.
14 r e t u r n oldExchange ;
15 }
16 } 5. REFERENCES
What makes the difference compared to a regular aggrega- [1] G. Hohpe and B. Woolf. Enterprise Integration
tion agent is, that one of the exchanges processed within the Patterns: Designing, Building, and Deploying
aggregation strategy is being retrieved by a sub-route that Messaging Solutions. Addison-Wesley Longman
queries the global state. The query is conducted based on a Publishing Co., Inc., Boston, MA, USA, 2003.
copy of the original incoming event. Listing 13 demonstrates [2] D. Chandrasekhar. Gartner predictions 2013 for
this behavior where the main route calls the sub route when application integration: My take. Technical report,
executing the enrich() expression. Reality Check, 2013.

267
[3] W. A. Ruh, F. X. Maginnis, and W. J. Brown. [14] N. M. Josuttis. SOA in Practice - The Art of
Enterprise Application Integration: A Wiley Tech Distributed System Design. O’Reilly Media, Inc., first
Brief. John Wiley & Sons, 2002. edition edition, 2007.
[4] J. Strachan. Initial checkin of camel routing library, 03 [15] T. Berners-Lee, R. Fielding, and L. Masinter. Uniform
2007. resource identifier (uri): Generic syntax. Request for
[5] C. Ibsen. Apache camel was awesome from v1.0 Comments 3986, The Internet Engineering Task Force
onward. Technical report, DZone, 2013. (IETF), Network Working Group,
[6] The Apache Software Foundation. Apache camel. http://tools.ietf.org/pdf/rfc3986.pdf, January 2005.
Technical report, Apache Software Foundation, 2013. [16] M. Welsh. Seda: An architecture for highly concurrent
[7] The Apache Software Foundation. Happy 5 years server applications. Project report, Harvard
birthday apache camel. Technical report, Apache University,
Software Foundation, 2013. http://www.eecs.harvard.edu/ mdw/proj/seda/, May
[8] D. C. Luckham. Event Processing for Business: 2006.
Organizing the Real-Time Enterprise. John Wiley & [17] M Hapner, R. Burridge, R. Sharma, J. Fialli, and
Sons, 2011. Stout K. Java message service - the jms api is an api
[9] O. Etzion and P. Niblett. Event Processing in Action. for accessing enterprise messaging systems for java
Manning Publications Co., 2011. programms. Specification Version 1.1, Sun
[10] R. v. Ammon, C. Silberbauer, and C. Wolff. Domain microsystems, April 2002.
specific reference models for event patterns - for faster [18] Spring. Spring java application framework. Reference
developing of business activity monitoring Documentation 3.0, Spring Source,
applications. In VIPSI 2007, October 2007. http://static.springsource.org/spring/docs/3.0.x/spring-
[11] C. Emmersberger, F. Springer, and C. Wolff. Location framework-reference/pdf/spring-framework-
based logistics services and event driven business reference.pdf,
process management. In D. Tavangarian, T. Kirste, 2011.
D. Timmermann, U. Lucke, and D. Versick, editors, [19] R. v. Ammon, C. Emmersberger, T. Ertlmaier,
Intelligent Interactive Assistance and Mobile O. Etzion, T. Paulus, and F. Springer. Existing and
Multimedia Computing, number 53 in future standards for event-driven business process
Communications in Computer and Information management. In Proceedings of the Third ACM
Science, pages 167–177. Springer, 2009. International Conference on Distributed Event-Based
[12] D. C. Luckham. The Power of Events: An Systems, DEBS 2009. ACM, July 2009.
Introduction to Complex Event Processing in [20] F. Buschmann. Pattern oriented software architecture:
Distributed Enterprise Systems. Addison-Wesley, a system of patters. John Wiley & Sons, 1st edition,
November 2001. July 1996.
[13] C. Ibsen and J. Anstey. Camel in Action. Manning [21] P. Kolb. Realization of eai patterns with apache camel.
Publications Co., 2011. Studienarbeit 2127, Institut für Architektur von
Anwendungssystemen, Universität Stuttgart, 04 2008.

268

View publication stats

You might also like