Getting Started with Mirth (Part 1)
This is the first post in a 2 part series. The second post is here
Recently I posted about my positive experience when using Mirth by Webreach as an open source communication layer between one of our in-house applications and a third party and proprietary web service interface. That post received a large amount of attention (relative to my other posts :o) ) so now I will post a quickstart guide to creating a similar setup.
In this post I will go over the very basics of using Mirth (please dig in and play around with some more advanced options/configurations), specifically I will demonstrate how to use Mirth to read data from a database, package the data up in a SOAP envelope, send the data to a web service and process the SOAP response. I'll also show you how easy it is to monitor channels once deployed.
Once you've installed and opened Mirth for the first time you'll be presented with an empty dashboard - but it wont stay empty for long. This is where you'll see the status of your live channels, so let's build one! Part 1 of this post will deal with the channel source. Part 2 will deal with the destination.
Clicking on the 'Channels' link on the LHS opens a blank pane. Right-click anywhere in the blank pane and choose 'New Channel'.
The screen that opens will present you with 4 tabs: summary, source, destination, scripts. First thing's first - enter some summary data. I named my channel ("Jason's Sender Channel"), changed the 'Incoming Data' type to XML (most other options are specific to medical information systems), added a description and chose to encrypt stored messages and prune them from the database after 5 days. That's all I need from the summary tab for right now.
The source tab is where you'll specify where your data is coming from. There are plenty of options here as you can see from the (partially) displayed dropdownlist in the screenshot below. For my purposes I'll need a database reader.
For a SQL Server database I choose SQL Server/Sybase as the Driver. The URL is of the format jdbc:jtds:sqlserver://<host>/<database>. In my case it goes as follows:
1: USE [demodb]2: GO3:4: /****** Object: Table [dbo].[mytable] Script Date: 12/18/2008 22:49:20 ******/6: GO7:9: GO10:12: GO13:20:21: GO22:24: GO25:26:
Once completed, my source looks as follows:
Here's where things get cool...I want to specify what data gets passed to my destination and how I want that data to be formatted. The easiest way to do this is to use a transformer (on the menu on the LHS) on the source.
First thing is first: update your message template. In this case the inbound message template will be automatically created based on the database fields we are querying. I want to specify an outbound template that will be passed to the channel's destination. See the textbox outlined in red below:
To summarize, I changed the names of the field (my query prefixed them with the table name) and instead of using a single 'name' field, I created a 'first_name' and 'last_name' field.
Now that the message templates are ready there are numerous ways to map from the inbound message to the outbound message - all are performed in the message tree tab. The easiest by far is to drag a value from the inbound message template tree to the outbound message template tree. In the below screenshot I have dragged the value node under 'mytable_id' in the inbound tree onto the value node under 'id' in the outbound tree resulting in step #0 displayed in the middle section of the window. I will do this for the mytable_isactive and mytable_created_date fields.
To map the mytable_name to first_name and last_name we'll have to be a little trickier. Right-click the white space in the middle pane and click 'Add New Step'.
1: combinedNameString = msg['mytable_name'].toString()2: arrName = combinedNameString.split(" ")3: tmp['first_name'] = arrName4: tmp['last_name'] = arrName
Our finished transformer will look as follows:
In the next couple of days i'll post part 2 which will demonstrate using the channel destination to call a SOAP method, passing this info wrapped up in a SOAP envelope. Thanks for reading..