Stream Service

This is a big one!

Since launching Vinli, we've been on a relentless quest to deliver the highest quality, most accurate, real-time-est (is that a word?) vehicle telematics possible. Our new Stream Service provides a whole new way to access vehicle data. You can now establish a WebSocket connection with the Vinli platform that will forward telemetry messages for one or more devices as soon as we receive them.

Now we're approaching the point where we just can't get the photons/electrons moving to your server any quicker. For now, this is as speedy as it's gonna get, but who knows what improvements lay in wait on the hardware side though... ;)

Right now this only supports telemetry messages (what you would get from Telemetry Service), but we'll be adding events and other items in the near future.

The Basics

The Vinli Stream Service provides a WebSocket server that can stream telemetry messages from one or more devices to which an App has access. Apps can start as many sockets as needed and can subscribe to one or more devices on each stream.

For now, we are only sending telemetry messages, but we're planning to add more types of streams soon. Messages published on the stream will match up exactly with the messages retrieved from Telemetry Service through https://telemetry.vin.li/api/v1/devices/<DEVICE_ID>/messages, but you will get them as soon as the device sends them (give or take a few milliseconds for maths). You can see an example at the bottom of this post.

Getting Started

Starting up the stream is as easy as firing up your favorite WebSocket client. In this example we'll be using the "ws" module for Node.js.

You'll need to authenticate your connection in the headers or as part of the URL (assuming you set appId and appSecret to be your App's credentials):

Either way, you'll soon have a WebSocket authenticated in the same way as you would any other
service in the Vinli Platform. The server will send messages, both the telemetry messages
and administrative messages, and you will need to handle these events:

ws.on('message', (data) => {
console.log(data);
});

Subscribing

Once the connection is established you'll subscribe to devices and start receiving their telemetry messages immediately. (Note that, as with other services, a Bearer token will only allow you to subscribe to devices owned by the user that generated the token. Docs)

Subscriptions are created by sending a message that describes the subject of the subscription:

Handling Backpressure

As you subscribe to more and more devices, a stream can push a large amount of data through the socket. If your connection or application starts to fall behind, Stream Service will attempt to queue up messages to send. Every 30 seconds, a health message will be published that contains the current queue length as a way for you to see when limits are being approached: