Before starting this section be sure to retrieve your API key and the appropriate Sift URL for your provisioned environment. Instructions
on how to retrieve the API key and URL and can be found in the authentication section of the documentation.
This exercise demonstrates how to stream data into Sift using the Rust client library.
The objective is to read in data from a mock data source representing sensor data from our asset,
NostromoLV426, and then stream that data to Sift.
NostromoLV426 will contain a single velocity channel whose
values are of type double; this channel will belong to the mainmotor component.
For full code examples, documentation, as well as the library's source code, refer to the following:
For this exercise we will need sift_rs, rand, pbjson_types, chrono, and tokio_stream. Inside of your new Rust project:
We will also add Tokio to use as our asynchronous runtime:
Tokio
Note that we don't actually require the full feature set of Tokio. The Tokio runtime flavor to use is dependent on your requirements,
however, Tokio is required to work with sift_rs that is the runtime that tonic relies on.
Next we're going to define a data source which will provide us with mock sensor data. The data source will simply send a timestamp and a float
over the course of a minute and sleep for 0.5s between each send. This will represent the time-series coming from the velocity channel:
Now we will define our channels in a function called channel_configs. Right now we only have one velocity channel but
we are free to add more later.
Next, we will define a function called get_or_create_ingestion config which retrieves an existing
ingestion config
by client key or creates it if it does not exist. This function will use the channel_configs function that we created
in the previous step:
Client Keys
As mentioned in the ingestion config section, specifying
a client key is highly recommended as it simplifies lookups for users after creation as shown above.