Language Examples
This article helps you to set up a stream and start sending data to STRM Privacy, using your language of preference.
Missing your language of preference? Please contact us, and let us know which language is missing.
Start your own driver if it doesn't exist yet, with the details of the quickstart Sending and receiving manually and the existing open-source drivers.
Setting up a stream
This quickstart assumes that you have created an account on the console.
Using the language examples
In order to run these examples, you need the following:
- An input stream to send data to (if you don’t know how, learn how to create streams)
- The credentials for this stream.
The following demo applications show how dummy data can be sent with a certain frequency. The data that is sent is quite static and does not result in any useful patterns for analysis, however, it does show how data can be constructed and transferred to STRM Privacy.
Use strm listen web-socket (stream-name) to inspect the data that is being sent and to debug issues.
Currently (Aug. 2021) every example language has a different configuration file format. This is inconvenient and will be
fixed. We aim to standardize this to the format created with
strm create stream (stream-name) --save
, so that getting up-and-running becomes easier.
- Java
- Python
- Rust
- NodeJS
- Php
This example is also available on GitHub . Please see the repository for the readme.
Short steps to start sending data:
git clone https://github.com/strmprivacy/java-examples
cd java-examples
strm create stream demo
clientId=$(strm get stream demo --output json | jq -r '.streamTree.stream.credentials[0].clientId')
clientSecret=$(strm get stream demo --output json | jq -r '.streamTree.stream.credentials[0].clientSecret')
mvn package
java -jar target/java-examples-0.0.1-SNAPSHOT-jar-with-dependencies.jar \
$clientId $clientSecret
org.eclipse.jetty.util.log - Logging initialized ...
io.strmprivacy.driver.client.AuthService - Initializing a new Auth Provider
io.strmprivacy.examples.Sender - 204
io.strmprivacy.examples.Sender - 204
io.strmprivacy.examples.Sender - 204
...
This example is also available on GitHub. Please see the repository for the readme.
Short steps to start sending data
git clone https://github.com/strmprivacy/python-examples
cd python-examples
python3 -m venv .venv
. .venv/bin/activate
python3 -m pip install -r requirements.txt
strm create stream demo
clientId=$(strm get stream demo --output json | jq -r '.streamTree.stream.credentials[0].clientId')
clientSecret=$(strm get stream demo --output json | jq -r '.streamTree.stream.credentials[0].clientSecret')
python3 examples/sender_async.py --client-id $clientId --client-secret $clientSecret
DEBUG:strmprivacy.driver.client.auth:Initializing a new Auth Provider for SenderService
DEBUG:strmprivacy.driver.client.auth:authenticate
INFO:__main__:Event sent, response 204
INFO:__main__:Event sent, response 204
INFO:__main__:Event sent, response 204
...
This example is also available on GitHub. Please see the repository for the readme.
Short steps to start sending data
git clone git@github.com:strmprivacy/rust-examples.git
cd rust-examples
strm create stream demo
clientId=$(strm get stream demo --output json | jq -r '.streamTree.stream.credentials[0].clientId')
clientSecret=$(strm get stream demo --output json | jq -r '.streamTree.stream.credentials[0].clientSecret')
cargo run $clientId $clientSecret
initializing client
sending events..
Event sent: 204 No Content
Event sent: 204 No Content
Event sent: 204 No Content
Event sent: 204 No Content
Event sent: 204 No Content
...
This example is also available on GitHub. Please see the repository for the readme.
Quick steps getting started:
git clone https://github.com/strmprivacy/nodejs-examples
cd nodejs-examples
strm create stream demo
clientId=$(strm get stream demo --output json | jq -r '.streamTree.stream.credentials[0].clientId')
clientSecret=$(strm get stream demo --output json | jq -r '.streamTree.stream.credentials[0].clientSecret')
strm get stream demo --output json | jq '.streamTree.stream.credentials[0]' > assets/credentials.json
npm i
npm run sender
> nodejs-driver-example@1.0.0 sender
> ts-node ./src/sender.ts
Status 204
Status 204
...
This example is also available on GitHub. Please see the repository for the readme.
Quick steps getting started:
git clone https://github.com/strmprivacy/php-examples
cd php-examples
strm create stream demo
clientId=$(strm get stream demo --output json | jq -r '.streamTree.stream.credentials[0].clientId')
clientSecret=$(strm get stream demo --output json | jq -r '.streamTree.stream.credentials[0].clientSecret')
composer install
## send one DemoEvent to STRM Privacy:
php examples/send.php $clientId $clientSecret
For PHP there are no code generation tools (yet) available for schema classes. The DemoEvent class below has been
manually created. For every event schema, a similar class is needed. This class needs to implement
the \StrmPrivacy\Driver\Contracts\Event
contract.
Receiving data
See strm listen web-socket for a debugging view on the events.
See exporting to Kafka or batch exporters for production event consuming.