Skip to content

Latest commit

 

History

History
49 lines (33 loc) · 4.95 KB

Connectors.md

File metadata and controls

49 lines (33 loc) · 4.95 KB

Connectors guide

This page provides information on how to setup a connector for SmartIOT.Connector and how to write your own.

A connector is a component of SmartIOT.Connector that allows you to publish the information obtained from a device to an external receiver in form of an event. Such receiver can then elaborate on those events and perform application logic to generate write requests to SmartIOT.Connector. Those requests are then propagated to the underlying devices and written to them as requested.

Every connector should publish the messages contained in project SmartIOT.Connector.Messages serialized in any form suitable for that specific connector. Two kind of serialization are provided out of the box: Json and Protobuf.

Two kind of serialization are provided out of the box: single message and stream based.
See below for further details.

These are the connectors provided by SmartIOT.Connector out of the box:

Serialization of messages

Different connectors can choose the way they serialize messages over the wire. Sometimes the protocol used by the connector is able to delimit the boundary of messages by itself and sometimes it is not.
When the protocol is able to split each message in a sequence of bytes, then we can use the single message serializer.
When the protocol is not able to split each message, some extra bytes are needed to be sent on the network to mark the message type and/or length. In this case, the stream message serializer should be used instead, and extra logic must be put on the connector to decode the protocol and interpret the incoming stream.

In this case the protocol is able to split each message in single byte[]. If the origin of the message is known, such as a specific topic for MqttConnector, it is enough to deserialize the message with the desired implementation (json, protobuf, ...). Otherwise, it is necessary to determine the type of the message maybe write it on the first byte.

The two provided implementations are:

In case of a stream based serializer, the protocol itself does not split each message in a byte[], so it is the serializer duty to do that splitting. Moreover, the serializer must also distinguish each message by a byte marker inside the stream, because every message type comes from the same stream.

To determine the type of the message, a single byte prefix is used. These are the values used to discriminate the message type:

The two provided implementations are: