Receiving events over websocket

It’s nice to see some data when playing with the debugging endpoint. Use strm sim run-random demo to generate random data on the demo stream. stream.

In one terminal:

strm create stream demo --save
strm sim run-random demo (1)

Starting to simulate random streammachine/demo/1.0.2 events to stream demo.
Sending one event every 1000 ms.
Sent 5 events
1 you don’t need to specify credentials because you created the stream with the --save flag.

The strm egress command is used for showing the events in real time.

strm egress --help
Read from egress

  strm egress (stream-name) [flags]

      --client-id string       Client id to be used for receiving data
      --client-secret string   Client secret to be used for receiving data

client-id and client-secret are optional, but required if you didn’t create the stream with the --save option. See cli docs.

Now lets consume the events from the simulator; in another terminal do:

strm egress demo
  "strmMeta": {
    "eventContractRef": "streammachine/example/1.3.0",
    "nonce": 159456216,
    "timestamp": 1629202317371,
    "keyLink": "1e3a47c9-2b4a-4820-b16c-975a63d69d9d",
    "billingId": "demo8542234275",
    "consentLevels": [ 0 ]
  "uniqueIdentifier": "AW0ku+QlmuzFHUc5asuBS/S2aPhnJFRXMkd9Sl8Z",
  "consistentValue": "AW0ku+SxBlO/YwVHZ8kbq7PbRiS9UqoafqYsGrYm2p8=",
  "someSensitiveValue": "AW0ku+Tf+Plyd/WN6E4NEpEaBEGVBHReySSdbmrjacAe",
  "notSensitiveValue": "not-sensitive-5"
The debugging endpoint shows json values, even when the actual wire format is Avro binary in this case. This is to make it easier to inspect the values.

The Hard Way

We don’t have to use the strm command, we can use any websocket client to interact with the Stream Machine egress endpoint.

First generate an OAuth2 idToken as described here.

Here we use wscat to connect to the websocket endpoint.

wscat -H "authorization:Bearer $idToken" -c wss://
Connected (press CTRL+C to quit)
< {
  "strmMeta": {
    "eventContractRef": "streammachine/example/1.3.0",
    "nonce": -1234364567,
    "timestamp": 1629192610656,
    "keyLink": "57ff8035-ae35-4e82-9bf2-a4d0a544c89d",
    "billingId": "demo8542234275",
    "consentLevels": [ 0, 1, 2, 3 ]
  "uniqueIdentifier": "ARYe0czxEBMEC6jh5GWYicyvqBD0JBOMRoQSm2PO",
  "consistentValue": "ARYe0cxg2b9W++VYEMYKbZXLzgQf+cAkcZuqUh82lMw=",
  "someSensitiveValue": "ARYe0cwC5ImORtYRIzKPzaxKyjErTn/9fyGhVTseDxg=",
  "notSensitiveValue": "not-sensitive-48"

Note the encryption of all fields labelled PII in the streammachine/example/1.3.0 event contract.