Current Articles | RSS Feed
Apache ServiceMix (SMX) can boost your efficiency when you work on complex Java projects, because it integrates several popular technologies, allowing you to get a simple application ready quickly.
You could define SMX as an enterprise service bus (ESB) integration provider powered by OSGi. Using ESB helps developers create interoperating applications that respect the service-oriented architecture model. SOA defines a set of rules and principles in software design that allow developers to create little pieces of software that each create services as part of a bigger design scheme. For example, an enterprise email client may comprise many components: email, calendar software, RSS facilities, and so on. With SOA, instead of developing them all in one piece, and thereby perhaps creating obscure bugs and chunky code, one develops the components separately then glues them together by working with a platform like SMX. Components communicate using events: a component generates an event, an event manager routes it to its destination, where another component receives it and processes it, and perhaps generates its own event. If you read our article on ActiveMQ, you have the idea. Finally, OSGi (formerly the Open Services Gateway initiative) is a spec collection for a framework standard.
Before you start developing with SMX, I suggest you take a tour of its website and look at its documentation page. To use SMX, you must have Java 6 installed, because it isn't guaranteed to work smoothly with Java 7. Select a download directory on your machine, which may also be the work/binary directory, as you choose, then download the package you need.
After extracting the contents of the archive, go to the bin/ directory and type ./start, then ./servicemix. The software starts at a console, just like a Linux terminal, and you can start exploring it by pressing the tab key and playing with the commands. One command you will find useful is the one to enable the web console on port 8181. Type features:list to see all the installed components, then use grep to see if web console is installed:
./start
./servicemix
features:list
karaf@root> features:list | grep web
By default the web console is not installed; you can run features:install webconsole to install it. You can install ActiveMQ's web console as well with a similar command, should you choose to. Yes, ActiveMQ is part of SMX, as is Karaf, the runtime behind SMX functionality; Camel, the integration framework; and CXF, the services framework. SMX also includes Jetty, a web server written entirely in Java, and once you've installed the web console, you can manage Karaf from a browser at http://localhost:8181/system/console, with smx/smx as user/password pair.
features:install webconsole
http://localhost:8181/system/console
To get started learning SMX, try this simple example that uses Blueprint, a part of the Apache Aries project. Blueprint, according to its website, "provides a dependency injection framework for OSGi and was standardized by the OSGi alliance." In frameworks such as these, services can become unavailable even though other services might still depend on them. With Blueprint you can write an XML file, include the necessary element with code like xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0, and you're good to go. Take a look at this example XML code:
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0
<?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> <camelContext xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="file:input"/> <log message="Copying ${file:name} to the output directory"/> <to uri="file:output"/> </route> </camelContext> </blueprint>
In this code, the xmlns attribute stands for XML NameSpace. xmlns is also used in XHTML, so there's a great chance you've seen it before. In XML, namespaces have the same puropse and meaning as they do in every other language that uses them: They avoid conflicts between element names, so when you want to group logically similar and unique elements, you use namespaces. Next, xsi stands for XML Schema Instance, and as you can see, this directive indicates the physical location of the schema documents. The lines containing from, log, and to are the core of our XML file; they define the source and the destination of the test file, as well as the log message. Do not dismiss logging; later, when your code becomes more complex than this 15-line XML file, you will need it to debug things. It's common programming practice to use printfs, couts, echos, or other functions used for outputting text to see where a problem lies. Finally, you can replace input and output with something more imaginative if you so desire, and please note how the file is copied into the output directory.
from
log
to
input
output
Now copy this file, naming it as you feel appropriate, into the deploy/ directory inside the SMX installation. Restart ServiceMix by running the commands ./stop and ./start inside the bin/ location. If you then enter the shell and look at the logs (with log:display) you will see the message defined in the XML code above. You can alter the file at your discretion to see how SMX works.
./stop
log:display
Using SMX implies finding out about a lot of other interesting technologies. Once you start working with it, you will find yourself learning about new and exciting things as you create your applications.
Allowed tags: <a> link, <b> bold, <i> italics