Wednesday, September 1, 2010

A TIBCO BusinessWorks-based file gateway – Part 2

In the previous article, we went through the steps to create a TIBCO BW process that parses a flat CSV file and transforms the data format from CSV to XML. Along the process we also transformed the data model, concatenating the firstname and lastname fields into a single element specified in the employee.xsd.
This article adds a file poller process with Render XML activity and sets up a few global variables for configurations. At the end of this article, we will have something like this.
image

For now, the following are configurable:
  • Inbound directory: DirInboundFolder (default to 'c:\fgw\inbound\')
  • Outbound directory: DirOutboundFolder (default to 'c:\fgw\outbound\')
  • Semaphore file extension: InboundSemaphoreExt (default to 'done')
  • Semaphore extension separator: InboundSemaphoreExtSeparator (default to '.')
  • Search pattern: InboundSemaphorePattern (default to '*')
Steps
This article assumes that you already knew how to perform basic tasks in TIBCO Designer.
1) Add a new folder under the FileGateway root folder.
2) Add a new process definition with a name PollEmpsCSV
3) Double-click the newly created process definition. Add a File Poller activity into the process. Note that the original ‘Start’ activity is now replaced by the File Poller activity.
4) Configure the File Poller activity.

In the Configuration tab, paste the following string into the File Name field:

%%DirInboundFolder%%%%InboundSemaphorePattern%%%%InboundSemaphoreExtSeparator%%%%InboundSemaphoreExt%%

The global variable name surrounded by double % signs will be resolved during run time.
image

In the Advanced tab:

image
5) Expand the ParseAndTransform folder in the Project Panel. Drag the 'ParseAndTransform' process into the PollEmpsCSV process. Wire the PollDumpCompletion activity, ParseAndTransform process and the End activity in the following order.
image 
6) An input parameter has already been defined earlier in the 'Start' activity of the ParseAndTransform process. This parameter holds the fully qualified name of the file to be parsed by the parser. While the Poller activity polls for the semaphore file, we will need to construct the filename required. This step assumes that the semaphore file without the extension is the filename to be processed.

In the input tab of ParseAndTransform sub-process, click on the pencil icon to bring up the XPath editor.

image

Paste the following XPath formula into the formula pane.

tib:substring-before-last($PollDumpCompletion/ns:EventSourceOuputNoContentClass/fileInfo/fullName,string-length($_globalVariables/pfx:GlobalVariables/InboundSemaphoreExtSeparator) + string-length($_globalVariables/pfx:GlobalVariables/InboundSemaphoreExt))

The above XPath formula returns the filename required by the ParseEmpsCSV activity inside the sub-process. If the semaphore filename is
c:\fgw\inbound\emp001.txt.done
then the input filename to the parser activity will be
c:\fgw\inbound\emp001.txt
There are different ways to implement semaphore. Another alternative is to rename the source file when the transfer/file creation by the legacy system has completed. Semaphore is required when writing large file that takes time to complete. This is to avoid the process from reading an incomplete file.

7) The ParseAndTransform sub-process provides 2 output elements in its output schema defined in its 'End' activity. Refer step 13 of part 1 of this article.
Add a render XML activity followed by a write file activity. The write file activity will use the filename specified in the 'outputFileName' element of the ParseAndTransform output schema.

8) For the sake of simplicity, add a 'Catch' activity that catches all unhandled exceptions.
image

The final process looks like this.

image
Download the entire project here and play with it!
There are a lot of works to be done for this gateway to be useful. The following considerations are in mind.

  • The semaphore file cleanup mechanism
  • The separation of write file activity into a sub-process
  • Error logging and resolutions
  • The 'execute-only-once' restriction
  • Refactoring of global variables, shared variables, and other considerations such as implementation of checkpoints for fault tolerance and load balancing.


Happy testing.

2 comments:

  1. Dear Kein,

    The way you presented the tutorial is awesome. I'm new to TIBCO. I could learn many aspects and various functionality available with this tool from this presentation.

    Thanks for sharing.

    I also would like to know, is there any books for TIBCO beginners.

    -Prasad

    ReplyDelete
  2. Hi Prasad,

    It is a common challenge for TIBCO beginners to grasp the concepts of TIBCO solutions. There aren't many books out there. Your most reliable source will be the product documentations. Just need to plough through the documentations and you will be fine.

    Another source I frequented was the TIBCO community, you can find answers to peculiar questions there.

    Good luck.

    ReplyDelete