You can use Server-Sent Events (SSEs) to get notified when the state of digital twins changes.
The client sends a request and server holds a connection until a new message is ready, then it sends the message back to the client while still keeping the connection open so that it can be used for another message once it becomes available. Once a new message is ready, it is sent back to the client on the same initial connection.
The SSE API for receiving change notifications is the /things endpoint:
http://localhost/things
When the endpoint is invoked with an HTTP header Accept with value text/event-stream, a Server-Sent Event stream of change notifications is created.
With SSE API /things you can only get notifications about specific changes. You specify the IDs of the Things and you can do:
SSE use cases
The use cases below show how to:
Use Case |
URI Subscription |
Result |
|---|---|---|
Create two Things with the following Ids:
Subscribe for all events for specific namespace |
/thigs?namespaces=<namespace>
For example:
|
Data: {"thingId":"test.server.sent.events:testThing_1","policyId":"test.server.sent.events:testThing_1","features":{"switch":{"properties":{"on":true}}}}
|
Delete two Things with the following Ids:
Subscribe for all events for specific namespace |
/thigs?namespaces=<namespace>
For example:
|
Data: {"thingId":"test.server.sent.events:testThing_1"}
{"thingId":"test.server.sent.events:testThing_2"} |
Change property on Change property level
Subscribe for all events for specific property |
/things?ids=<thingId>&fields=thingId,features/<second_feature_name>/properties/on |
Data: {"thingId":"test.server.sent.events:testThing_23","features":{"secondSwitch":{"properties":{"on":true}}}}
|