Applications in the business world do not live in isolation, they have to cooperate and share information between themselves. In the ideal world applications can talk to each other without any problems and platform independence is commonplace. In the real world there are often silos of massive amounts of data, which are often redundant, sometimes very complex, hardly ever is it easily shared, and true platform independence is a fairy tale. It is in this world, the real world, that the hard work of integrating applications together takes place.
Enter, the Simple Integration Framework (a.k.a SimpleInt). SimpleInt is a new open source project on the CodePlex web site.
This is a simple demonstration of how to use SimpleInt to allow data to be shared from one system to another. The basic components of an integration package in the SimpleInt Framework consist of a listener, a parser, a transformer, and a sender. In this article we will walk through setting up each of these components to integrate two applications together.
SimpleInt is an integration framework in the very early stages of development. Currently there is an implementation of a simple and very configurable message broker in the framework. A good place to go for an overview of the message broker pattern is http://www.patternshare.com/.
Let’s Get Started
For simplicity’s sake the example we are going to work on in this article uses the file system as the transport medium from one application to another. Our first hypothetical application places output files in one file folder and our second hypothetical application reads files from an input folder.
The integration package that we are going to create will poll the first applications output folder for new files.The integration package will read those files in and apply an XSL transform to them and place the output in our second applications input folder.
Now, we will go ahead and create an xml file that will be our input file. Let us name it
input.xml and it should read as follows:
Now, create an XSL transform named
changIt.xslt that will change this xml document into another xml format.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
Now that we know our input and have defined our output format, create a project. Since a great company like Northwinds is always expanding and looking for new opportunities let’s go ahead and get them into the Healthcare market since our input and output data deals with going to see the doctor.
- Open Visual Studio 2005 and create a new Winforms project named
- Add a reference to the
- Include our input file,
input.xml, and the XSL transform
changeIt.xslt in the project. Flag the
changeIt.xslt file to always be copied to the output directory.
- Add a button to
Form1 and change its text to “Start”.
- Add another button, change its text to “Stop”, and set its enabled property to
Now your form should look like this:
Now let us add some code to the form.
_sm = new SimpleInt.Framework.ServiceManager();
We added a SimpleInt
ServiceManager field to the form class and initialized it in the form constructor. All the code we will write to manipulate the SimpleInt framework will be against this class, and there’s not a lot of code that we will write.
Now let’s start the service manager in the
Start button click event.
private void button1_Click(object sender, EventArgs e)
button1.Enabled = false;
button2.Enabled = true;
And stop the service manager in the
Stop button click event.
private void button2_Click(object sender, EventArgs e)
button1.Enabled = true;
button2.Enabled = false;
Believe it or not, we are done coding. The rest of the article we will be setting up and configuring the service manager. We will use some of the simple implementations of parsers, listeners, translators, and senders that are already built into the SimpleInt framework. You could easily extend the framework by implementing your own parsers, senders, translators, or listeners and, in fact, that is exactly what the creators of the framework envision many developers doing. But this is a simple demonstration so we will stick to the basics.
Configuring the Service Manager
App.config file to the
NorthwindsMedical project. In that
App.config add the following
type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
This declares the
IntegrationConfig section in which we will configure the SimpleInt service manager, the
nhibernate section in which we will configure our database connection, and the
log4net section which we will not use but NHibernate and Spring.NET need.
Now we need to setup a database. (Note: In this example we will use a MSSQL Server as our data store but NHibernate allows for pretty good database independence. MySQL, Oracle, and others are supported by NHibernate out of the box and the SimpleInt framework does not care where its data is stored.) Run the
CreateMessagesTable.sql script against the MSSQL Server database you want to use for this example. With the database now set we can add the following NHibernate configuration info to the
user id=someuser;password=somepassword" />
Now change the
hibernate.connection.connection_string value to the connection string for the database you ran the
CreateMessagesTable.sql script against.
Now add the following to the
This is the section where most of the magic is going to happen. We will come back to this soon.
Add the following to the
App.config to keep
Now back to the meat of the configuration. Inside the
objects tags in the
IntegrationConfig section we are going to wire up an instance of the
SimpleInt.Framework.Processor class. Add the following xml inside the
It is very important that the
name of this
object be correct (
IntegrationProcessor) because it is the name that the SimpleInt service manager will be looking for. Notice that we have configured this class as a singleton, so only one instance of this object will be created for the life of the service manager. Also, we have set the
IntegrationPackages properties. The
DataStore property references an object named
IntegrationDataStore, which we will configure later. The
IntegrationPackages property is a collection, so any object that needs to be added to that collection goes in between the
Now let’s set up the
TestPackage integration package and all of its supporting objects. Add the following xml inside the
Notice we are using a
TestParser) and we are using the
XsltTranslator, which we have configured to use the
changeIt.xslt file we created earlier. We are also using a
FilePollingListener and a
So based on the configuration above, the listener will grab any file placed in the
Input folder, read it into the system as a new message, and move it to the
Archive folder. The parser will just pass the message on to the translator as is. The translator will apply the
changeIt.xslt transform to the message and the sender will write the translated message to the
Output folder as a new file with a “.out” file extension.
Now we need to add the folders mentioned above in the right place. In your project output folder (ususally
bin\Debug) create three folders:
Sweet… Not too bad for 3 lines of SimpleInt specific code and some xml.
Now let’s finish up and configure the data store. Add the following xml inside the
Here we are just configuring and initializing the
SimpleDBDataStore, which uses NHibernate to handle database calls to store and log the messages that are processed.
Now we are ready to run it.
Running the Demo
Now hit F5 to build the project and run it. When
Form1 pops up, push start. After you click the “started” message box, put a copy of the
input.xml file into the
Input folder. That file should disappear from that folder in a second or so. After it has disappeared, verify that a copy of the
input.xml file is now in the
Archive folder and that a new file is in the
Output folder. The contents of that file should be the contents of the input file translated into the format that our second application needs, and it should look like this:
Again, not too bad for 3 lines of SimpleInt specific code and some xml, is it?
Points of Interest
The ability to wire objects together in a config file and then have an application run based on that wiring is pretty cool. Spring.Net has some great dependency injection and inversion of control abilities. Also SimpleInt has plans to add a message bus set of features as the framework grows.