The aim of this blog is to introduce you to Enterprise Integration Patterns and to show you how to create an application to integrate Alfresco with an external application…in this case we will be sending documents on request from Alfresco to Box based on CMIS queries. We will store both the content and the metadata in Box.
EIP (Enterprise Integration Patters) defines a language consisting of 65 integration patterns (http://www.enterpriseintegrationpatterns.com/patterns/messaging/toc.html) to establish a technology-independent vocabulary and a visual notation to design and document integration solutions.
Why EIP? Today's applications rarely live in isolation. Architecting integration solutions is a complex task.
The lack of a common vocabulary and body of knowledge for asynchronous messaging architectures make it difficult to avoid common pitfalls.
For example the following diagram shows how content from one application is routed and transformed to be delivered to another application. Each step can be further detailed with specific annotations.
The following example shows how to maintain the overall message flow when processing a message consisting of multiple elements, each of which may require different processing.
Apache Camel (http://camel.apache.org/) is an integration framework whose main goal is to make integration easier. It implements many of the EIP patterns and allows you to focus on solving business problems, freeing you from the burden of plumbing.
At a high level, Camel is composed of components, routes and processors. All of these are contained within the CamelContext .
The CamelContext provides access to many useful services, the most notable being components, type converters, a registry, endpoints, routes, data formats, and languages.
A Component is essentially a factory of Endpoint instances. To date, there are over 80 components in the Camel ecosystem that range in function from data transports, to DSL s, data formats, and so on i.e. cmis, http, box, salesforce, ftp, smtp, etc
An endpoint is the Camel abstraction that models the end of a channel through which a system can send or receive messages. Endpoints are usually created by a Component and Endpoints are usually referred to in the DSL via their URIs i.e. cmis://cmisServerUrl[?options]
The steps taken to send a message from one end point to another end point.
Camel provides a built-in type-converter system that automatically converts between well-known types. This system allows Camel components to easily work together without having type mismatches.
Allow messages to be marshaled to and from binary or text formats to support a kind of Message Translator i.e. gzip, json, csv, crypto, etc
Contains a registry that allows you to look up beans i.e. use a bean that defines the jdbc data source
To wire processors and endpoints together to form routes, Camel defines a DSL. DSL include among other Java, Groovy, Scala, Spring XML.
The aim of the application is to send documents on request from Alfresco to Box. We will store both the content and the metadata in Box.
To build an EIP Application we are going to use:
The full source code is available on GitHub: https://github.com/miguel-rodriguez/Alfresco-Camel
The basic message flow is as follows:
Apache Maven (https://maven.apache.org/) is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.
For our project the pom.xml brings the required dependencies such as Camel and ActiveMQ. The pom.xml file looks like this:
Spring Boot (https://projects.spring.io/spring-boot/) makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". Most Spring Boot applications need very little Spring configuration.
We use the applicationContext.xml to define the java beans used by our application. Here we define the beans for connecting to Box, Database connectivity, ActiveMQ and Camel. For the purpose of this application we only need ActiveMQ and Box connectivity.
The Application class is used to run our Spring application
In the Route.java file we define the Camel routes to send traffic from Alfresco to Box.
The code below shows the routes to Execute cmis query, download content and properties, compress it and upload it to Box
Let’s break it down…
1. We read requests messages with a CMIS query from an ActiveMQ queue
For example a CMIS query to get the nodes on a specific folder looks like…
|SELECT * FROM cmis:document WHERE IN_FOLDER ('workspace://SpacesStore/56c5bc2e-ea5c-4f6a-b817-32f35a7bb195') and cmisbjectTypeId='cmis:document'|
For testing purposes we can fire the message requests directly from the ActiveMQ admin UI (http://127.0.0.1:8161/admin/)
2. We send the CMIS query to Alfresco defined as “alfrescoSender”
|.to(alfrescoSender + "&queryMode=true")|
3. Alfresco sender is defined in application.properties as
and mapped to “alfrescoSender” variable in Route.java
4. We store the files retrieved by the CMIS query in the filesystem using class FileContentProcessor for that job
5. Zip the content file and the metadata file
6. And finally upload the content to Box
To build the application using maven we execute the following command:
Hawtio (http://hawt.io) is a pluggable management console for Java stuff which supports any kind of JVM, any kind of container (Tomcat, Jetty, Karaf, JBoss, Fuse Fabric, etc), and any kind of Java technology and middleware.
Hawtion can help you to visualize Routes with real-time updates on messages metrics.
You can get statistical data for each individual route.
I hope this basic introduction to EIP and Apache Camel gives you some idea on how to integrate different applications using the existing end points provided by Apache Camel.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.