The following describes the process of making a message to be run on a nano service.
Add a NanoService in Services in the Busby configuration and call it calc
. You can create several messages. Each message can be a subroutine of the calc service.
The first message has been called "add"
// Incoming message is accessible from the message variable.
// Use busby.result to send return payload.
busby.result({
number: message.params.number1 + message.params.number2
})
The second message has been called "subtract"
busby.result({
number: message.params.number1 - message.params.number2
})
To use the new NanoService we can create a Script step in a Workflow. Then we will use busby.send to access the "calc" NanoService.
The first parameter is used for the name of the NanoService: "calc". Then we send the message or subroutine that we want to run, followed by the parameters in curly brackets.
let number_1 = 25;
let number_2 = 10;
const addNum = busby.send("calc", "add", { number1:number_1, number2:number_2 });
const subNum = busby.send("calc", "subtract", { number1:number_1, number2:number_2 });
To output the returned values we add a json object and display it in a busby.stateStore
const json = {
addNumber: number_1 + ' + ' + number_2 + " = " + addNum.params.number,
subtractNumber: number_1 + ' - ' + number_2 + " = " + subNum.params.number
};
busby.stateStore.updateJsonInfo("NanoService example", json);
This will then appear in a tab titled "NanoService example"
Add Number 25 + 10 = 35
Subtract Number 25 - 10 = 15