Tutorial: RSSBus AppServer Events

RSSBus apps can raise events when a particular condition is met. In the RSSBus AS2 Connector app, for instance, sending a file raises two events: BeforeSend and AfterSend. The power of these events lies in the ability to respond to them with, say, running a batch file or shell script. This tutorial shows you how to automate actions in your operating system after an RSSBus app raises an event.

Learning what events an application offers

To find out what events an app makes available, log in to that app and navigate to the Services page. On the left-hand panel, scroll down to the Events section. You will see listed the events available for a given app.

If you click on one of the events, it lists some information, including the event parameters. These are bits of data you can use within the script that executes in tandem with that event. Below that, in the Configuration section, you will see a description of events, including the path to the selected event.

A Simple Example: Running a Batch File After Sending a File in AS2 Connect

AS2 Connector sends and receives files to and from trading partners. Often times it is useful to execute a batch when a file is sent from AS2 Connector, so for this example, we'll be working with the AfterSend event. Go to the AfterSend event listed in the Events section of the left-hand column on the Services page. Under the Configuration section, note the path to the events directory and navigate to it in your file system.

In the events directory, you will see several files. Open the AfterSend.rsb file in your flavor of text editor. You will see several blocks of XML, including a few commented blocks. The commented blocks are pre-baked scripts that perform common and useful tasks. The first two comment blocks respectively pertain to Windows batch files and UNIX shells scripts. The directions for either option are identical in this tutorial, but we'll use Windows batch files here for simplicity's sake.

First, uncomment the batch file code block so it looks like this:

<rsb:set item="batchInput" attr="name" value="C:\myfile.bat" />
<rsb:set item="batchInput" attr="arguments" value="[AS2From] [File]" />
<rsb:call op="sysExecute" input="batchInput" />

Let's unpack this brief triplet of code. The prefix rsb indicates the XML tag is an RSBScript command. RSBScript is the scripting language of RSSBus.

You see there are two rsb:set tags. These tags set up the inputs to the rsb:call tag on the third line. Notice the rsb:set tags have three attributes: item, attr, and value. For the first rsb:set, we set the location of our batch file to the name attribute of the batchInput item. You will want to edit the value to point the location of your own batch file.

We do something similar in the next rsb:set tag. This time, we are setting the arguments of the batch file itself. AS2From and File are inputs to the AfterSend event. All of the inputs are listed in the rsb:info block near the top of the script.

Also notice the square brackets around the input names: this resolves the value of those inputs. Say for instance the values of AS2From and File were "MyPartner" and "C:\test.xml", respectively. Then, according to our rsb:set command, the arguments attribute of the batchInput will equal MyPartner C:\test.xml. Again, you will need to edit this value to match the inputs of your batch script.

Finally, the rsb:call tag calls the sysExecute operation using our batchInput item. This tells the operating system to execute a process as specified by our batchInput.

Taking Control of Events

After you've successfully enabled your batch file or shell script to execute when an event fires, the actions you can perform are limited by the capabilities of your system. This is a powerful tool for triggering processes on your system or even services within an RSSBus app.

 
 
Products