Tutorial - My first flow

In this tutorial we are mimicking a scenario where we receive temperature data from a sensor and storing the output to a file location.

Reviewing the sample flow

Open the flow by clicking the Edit link next to your flow. This will take you to the details page of your flow, and a designer should open up looking like the one below:

The flow is built up of three services; A temperature sensor, a JavaScript and a File service.

Inbound Simulator Temperature Sensor

To quickly get started we’ll simulate the temperature sensor for now. Later on, you can easily change this service to a real sensor service from the toolbox. The simulator generates a new message every 10 seconds. You can change the interval by right-clicking the service, select Properties from the context menu to open the Properties window. Click the Static Properties tab and change the interval (s).

JavaScript Service

Because we don’t get a timestamp from the temperature sensor, we’d want to add it to the message payload. We can easily do this using a scripting service. Right-click the JavaScript service and select Script from the context menu to view the code.

Outbound File Service

The last service is the File Outbound Service which will save the payload to disk. Open the properties window of the File service and click the Static Properties tab. The Outbound File service has three parameters:

  • Path – the folder where the file is going to be saved.
  • File name – the name of the file
  • Create directory – create the directory if it doesn’t exist. The Path in this case points to a folder where you want to store the output from this service. In this sample it points to c:\ temp\samples\1\out, but feel free to change this to any other directory on your machine or device.

The File name property is using a service macro to set the name. Service macro are specific to each service. The %guid% macro will give you an unique name of the file.

There are three other ways to set properties, and you can combine them as with this sample:

  • Static – simply set the name of the property Eg: myFile.txt
  • By using brackets you refer to message content Eg: [orderId]
  • By using curly brackets you refer to message variables Eg:

Good to know

We’ll talk more about message variables in later modules, but it can be good to know that you can set variables in a flow. Many of the services is setting variables automatically. These variables are prefixed by underscore. For instance, the File Inbound service is setting _fileName, _fileExtension and _fullPath.

Try it out!

Save the flow

When you examined the properties of the File Inbound service in the previous step, you might have noticed that the Node property on the General tab of the Properties dialogue was set to “nodeJs-0001”. Before you save a flow this property has to be set. However, you have likely not created any Nodes yet. If no Node exist with this name it will automatically be created for you.

Click Save.

Create Node

The node applikation that runs on your device is an open source application built in Javascript on top of Node.js. Node.js is a Javascript run-time based application plattform. For more detailed information about installing the node, please have a look at the "Installing a node" section under "Common Tasks and Walkthroughs".

Good to know

There are three ways a Node can be created:

  • By creating it on the Nodes page Through saving the flow (as with this sample)
  • When starting the Node for the first time using a verification code.
  • Navigate to the Nodes page using the menu or by using Ctrl+r and type node [Enter].

On the Nodes page, your new Node named “nodeJs-00001” should be visible.

Install node.js

Open a new browser window and navigate to http://nodejs.org. Download node.js 4.* (We currently don't support version 5.* of node.js) and follow the instructions of how to install it.

Install microservicebus.node

microservicebus.node is a node.js package you can install using node package manager – npm. Follow the steps to install microservicebus.node:

  1. Create a folder anywhere on your machine or device. This folder will be the folder where you install the node.
  2. Open a terminal, PowerShell or command window and navigate to the folder you just created.
  3. Type npm install microservicebus.node. Hit Enter.
  4. After the installation has completed, type cd node_modules/microservicebus.node to change to install folder.

Starting the Node

The last step is to configure the Node. To make sure no one else connects their Nodes to your organization we need to create a Verification code. The verification code can easily be generated from the Node page.

  1. Go back to Node page on microservicebus.com and click the Generate button.
  2. Copy the code to the clipboard.
  3. Back in the terminal type: node start.js /c [YOUR CODE] /n nodeJs-00001 Because this is the first time we create a Node on this machine or device, the Node is calling up to the Hub to get the configuration for the node named “nodeJs-00001”. The settings are downloaded and stored in the settings.json file.

After the node has signed in successfully, it will download the scripts for the simulator, Javascript and file services, and start all services.

Examine the output

As your flow in running you should now see files created in the folder.

[microservicebus.node installation folder] /output/samples/1/out

Well done.