Sequence that reads incoming stream (input), and and modifies it by adding a text message according to the incoming data.
Stream is generated in stream-gen.js file, where numbers in range of <-50,50> are randomly chosen and sent as Celsius degrees to hello-snowman
Instance API endpoint /input
.
Our hello-snowman
app will read and interpret these Celsius degrees, and will inform us about state of our Snowman:
- if temperature will be 0 or below, Sequence will return message:
Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️
- in the other case (temperature above 0 degrees), Sequence will return message:
Snowman ⛄ is melting! 🥵
This sample can be run only on Self Hosted Hub, go on and setup transform-hub locally for the sequence deployment.
Open three terminals and run the following commands:
The first terminal:
# start the Hub locally
scramjet-transform-hub
The second terminal:
# go to 'hello-snowman' directory
cd javascript/hello-snowman
# install dependencies
npm install
# go back to javascript/ directory
cd ../
# deploy 'hello-snowman' Sequence
si seq deploy hello-snowman
# see the Instance output
si inst output - # nothing happens until data is sent to input
💡NOTE: Command
deploy
performs three actions at once:pack
,send
andstart
the Sequence. It is the same as if you would run those three commands separately:
si seq pack . -o hello-snowman.tar.gz # compress 'hello-snowman/' directory into file named 'hello-snowman.tar.gz'
si seq send hello-snowman.tar.gz # send compressed Sequence to STH, this will output Sequence ID
si seq start - # start the Sequence, this will output Instance ID
The third terminal
# Start stream generator tool with Instance ID as parameter
node javascript/hello-snowman/lib/stream-gen.js <instance_id>
#
----------------------------------------
Message# 1 | Temperature measure
INPUT | -16
OUTPUT| Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️
----------------------------------------
Message# 2 | Temperature measure
INPUT | 49
OUTPUT| Snowman ⛄ is melting! 🥵
----------------------------------------
Message# 3 | Temperature measure
INPUT | 16
OUTPUT| Snowman ⛄ is melting! 🥵
----------------------------------------
Message# 4 | Temperature measure
INPUT | -46
OUTPUT| Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️
----------------------------------------
Now you should see the output in the second terminal:
$ si inst output -
Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️
Snowman ⛄ is melting! 🥵
Snowman ⛄ is melting! 🥵
Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️
Snowman ⛄ is melting! 🥵
Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️
Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️
Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️
Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️
Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️
Snowman ⛄ is freezing 🥶 Winter is coming ❄️ ❄️ ❄️ ❄️ ❄️
Snowman ⛄ is melting! 🥵
Snowman ⛄ is melting! 🥵
Snowman ⛄ is melting! 🥵