Message Image  

App Connect

Using F# with .NET in IBM Integration Bus 

Tue June 02, 2020 11:54 AM

This post outlines one way of using F# in IBM Integration Bus (IIB). F# gives you another option for writing intuitive and maintainable code for message processing.

What is F# ?
F# is a .NET programming language, incorporating functional programming concepts similar to those found in languages such as Haskell. F# can allow a programmer to express their intentions more directly, resulting in maintainable and reliable code. You can use F# to create a .NET assembly that you invoke from a .NETCompute node or from ESQL.

What do I need?
– a Windows installation that includes Microsoft .NET Framework V4 or later
– IBM Integration Bus / WebSphere Message Broker V8 or later
– Microsoft Visual Studio 2010 (Express Edition or Professional Edition) or later

This is not an introduction to functional programming or to using .NET in IIB. These are explained really well elsewhere, for example in the following developerWorks articles: (PDFs also attached)
Using Microsoft .NET in WebSphere Message Broker V8
Functional thinking: Thinking functionally
Beginning Haskell

F# message processing example
The IIB flow we’re going to create is simply:

Input(XMLNSC domain)   -   .NETCompute   -   Trace   -   Output

You can use any supported transport – for example, HTTPInput / HTTPReply for the input and output nodes. The Trace node is not essential, but just allows you to check the logical tree structure generated by your F# code.

For development and testing we can specify the location of our .NET assembly (dll) directly as a property on the .NETCompute node. This has the advantage that when we rebuild the Visual Studio project, the modified assembly is immediately picked up by the IIB flow. To gain more control in a production environment you can use a configurable service to specify the location of the assembly.

The flow takes an XML message containing a set of stock prices for a company, and adds a <summary> folder with various metrics calculated from the raw data.

Here is an example input message. Each <data> element is a comma delimited list giving the data, then the opening, highest, lowest and closing stock index:

If you use aggregation in IIB, you could imagine receiving an aggregated message with multiple sets of data like this.

How should we handle the comma delimited data in each element? Complex delimited data formats are usually best handled by DFDL. In this case, however, the data is quite simple and we’ll ‘parse’ it in the F# code. First we need to create an F# project in Visual Studio.

Using Visual Studio
When IIB is installed on Windows, a number of broker-specific templates are made available to your Visual Studio installation.

Under Templates, select Visual F# and IBM Integration [or Message Broker], then select the template to Modify an IBM Integration [or Message Broker] message.

Open the source file created (e.g. ModifyNode.fs) and edit the Evaluate method to build the required output message.

The F# Code

Here is the outline F# code, showing the Evaluate method that will process the stock data and update the output message. The code is explained in the comments.

The output message will be a copy of the input message, with the addition of a new <summary> folder, incorporating the metrics explained in the code.

What sets this apart from other IIB transformation options is the way we can use the built-in F# support for lists and functional composition to process the data. Whether you find this code intuitive may depend on your programming background, but I hope you’d agree that it is concise and should be easy to maintain and modify.

I’ve discussed one way of using F# in IIB. I hope you’ve found this very brief introduction useful. It would be interesting to know if you have seen any real-world use of IIB yourself where this style of coding could be useful. Thanks for reading!



0 Favorited
3 Files
pdf file
Beginning Haskell An introduction to functional programmin   241 KB   1 version
Uploaded - Tue June 02, 2020
pdf file
Thinking functionally, Part 1 Learning to think like a fu...   208 KB   1 version
Uploaded - Tue June 02, 2020