1.3 Embedded Microservices

Watch this video to learn how to reuse services as embedded microservices.

In the previous video we built a DiceRoll microservice. We are now going to take this a step further, and build a microservice that rolls two die and returns the sum of the two.
Warewolf allows you to reuse microservices as components, so we can reuse the DiceRoll microservice that we just built as a component.
First, create a new microservice.

Next, we are going to reuse your original DiceRoll microservice as a component. As mentioned a little earlier, you can drag resources from the Explorer onto your design surface, just as you drag tools onto the design surface.

When you drop a resource onto the design surface from the Explorer, it will open in Large view. Most tools and resources have both a Large view and Small view. The Large view of a tool or resource shows all of the available configuration options. If you look at the large-view Result field you will see it contains the variable called [[Result]] that we originally assigned in the Random tool in the DiceRoll microservice. Warewolf automatically assigns the variable names that you originally assigned.
I will double-click the icon bar located at the top to return this to small view.
If we look at the Variables list, you can see that when you dragged on the DiceRoll microservice, Warewolf automatically created a variable called [[Result]] in DoubleDiceRoll too.

Because we want to roll two die we are going to reuse the DiceRoll microservice as a component.

Drag on a second DiceRoll microservice, and connect it below the first one in the workflow.
The Result variable in the embedded microservice is assigned to an internal variable called [[Result]]. The same issue applies to both of the embedded DiceRoll microservices. What we need to do is assign unique internal variable names to both.

Change the mapped variable name to [[Dice1]] for the first DiceRoll, and for the second DiceRoll, change the mapped variable name to [[Dice2]]

Warewolf has automatically created the two new variables. Notice the small trash icon next to [[Result]].
The trash icon displays because the [[Result]] variable is no longer being used in the workflow. To remove it, simply click the trash icon.We want our microservice to output the results of the double dice roll, so we need to flag the Dice1 and Dice2 variable as an Output variable, using the checkbox in the Variable List, like we did previously.
At this point, the DoubleDiceRoll microservice is ready to start up, run DiceRoll, run DiceRoll again, and then end.
Using the debugger, you can examine how a workflow runs in detail. To see the debug output for DoubleDiceRoll, click on the Debug Button on the Toolbar.
The Debug dialog window displays in the middle of the screen. Click the Debug button on the dialog window to run the microservice in Debug mode.
Instead of using the Toolbox Debug button, you can also use shortcut keys: F6 runs the debugger, and F7 views the output in your browser.

Let’s have a look at what the debug Output looks like for DoubleDiceRoll. The debug output window is located below the variable list to the right of your design surface. The debug output displays detailed output for each step in the workflow.

Service: We can see that the DiceRoll service is being run here, even though we are actually working in the DoubleDiceRoll service.
Server: We haven’t touched on this yet, but in the same way you embedded two DiceRoll microservices into DoubleDiceRoll, you can also embed microservices from remote Warewolf servers. This means that your microservice can actually run and receive output from a Warewolf server located anywhere on earth, simply by dragging and dropping the remote microservice into your workflow.
Type: Service is a connector or workflow. Each type of tool or resource that can be dropped onto the design surface has a Type.
End Time: The time, to the millisecond, when the step stopped executing.
Duration: This step executed for of a second.
Inputs: This microservice doesn’t have any input values, so the Input Value does not appear.
Outputs: [[Result]]=1. The dice roll returned the value of 1.
When you click on the steps in the debug output, a blue highlight frame appears around the debug step,  the corresponding step that is executing on the design surface is also highlighted in orange.
You can click through the debug steps and easily see in the flow what step is being executed. This is useful when you find an error in the debug output that you want to fix, because you can easily locate the tool where the error is occurring.

If we run the microservice in debug mode, the output looks like this.
Looking at Step 4, you can see that the microservice has the two output variables for [[Dice1]] and [[Dice2]] assigned. You can also see [[Dice1]] being assigned in Step 2, and [[Dice2]] being assigned in Step 3.
The next output we want to include in our microservice is the total of the two dice values. To do this, drag an Assign tool on to your design surface and add it to the end of your workflow.

Find the Assign tool in the Data category, or search for it by name in the Search Filter of the Tool Box.
In the field in the left add a new variable called [[DiceTotal]]. On the right add the two dice variables together by typing the following: = [[Dice1]] + [[Dice2]]

You will notice that soon as you type the “=” sign, the ”fx”symbol appears. This means you have entered formula mode. Warewolf has a powerful formula system built into variable assignment that is functionally and syntactically equivalent to Microsoft Excel.

Next, Flag [[DiceTotal]] as an Output variable .

When we run the microservice in debug mode now, the last two debug steps will look similar to the output earlier on. If we look at the Assign Inputs we see how Warewolf interprets our logic and produces a new Output Variable. The last debug step now shows three Output Variables, including [[DiceTotal]], which is the sum of [[Dice1]] and [[Dice2]]. If we run the Debug output in Browser mode (F7), you can see how Warewolf structures the XML output for multiple output variables. Refresh your browser to execute the microservice again for different random results.


Updated on June 22, 2018

Was this article helpful?

Related Articles

Enjoying Warewolf?

Write a review on G2 Crowd