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:
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).
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.
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.
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.
microservicebus.node is a node.js package you can install using node package manager – npm. Follow the steps to install microservicebus.node:
- Create a folder anywhere on your machine or device. This folder will be the folder where you install the node.
- Open a terminal, PowerShell or command window and navigate to the folder you just created.
- Type npm install microservicebus.node. Hit Enter.
- 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.
- Go back to Node page on microservicebus.com and click the Generate button.
- Copy the code to the clipboard.
- 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.
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