I am currently working on a great "Internet of Things" project, everything based on Microsoft Azure technology. To represent my "universe of devices" I use MSR Orleans to provide a statefull universe of devices that interact with the outside world. The whole solution is based around Service Bus technology where every device has it's own subscription on the "Command" topic. Users or systems drop their commands in this topic and depending on a SqlFilter the different devices pick up that command and act upon it (do some device-specific operation).
Look at the figure below how this looks (simplified).
Because I also want to be able to track the history of operations performed by devices I decided to use Orleans to represent each device in a so called "Grain". Go to https://orleans.codeplex.com for more information on Orleans and how to get this baby running on your Azure services.
At the time a device is provisioned (by himself or by some operator) a new Service Identity and Relying party is created on ACS. No use of HTTPS or whatsoever because managing thousands of certificates for each and every device is not a good idea. Besides, I don't want (from a security perspective) to connect directly to the device with some inbound socket connection but I want the initiative to be at the device side. Imagine a car driving around the country where internet connectivity is sometimes there and sometimes it isn't (inside a tunnel) and we also don't want to communicate with fixed IP since IP's can change in a roaming world.
So what do we have? Devices all over the country that:
- provision themselves with some deviceID at the server
- the server creates an identity and relying party application on ACS and return that information to the device (account + key)
- the device gets a URI to the a Service Bus topic where it can drop of it's events
- the device gets a URI to the subscription especially created for the device where it can listen to and act if some command appears on it.
At this time, devices can play a role in the ecosystem. To involve Orleans in this scenario I create another subscription on the "event" topic (obviously there will be multiple subscribers on this topic in a production environment). This subscription is used to kick off Orleans and operate on "Grains" that represent a device. A grain is created (implicitly) once a device is provisioned. From that point, the grain lives forever (unless the devices gets deleted) and maintains state of the device and also keeps track of the history, heartbeats and so on.
Because I want to reflect als these updates that take place on the devices' status I also create one grain that is responsible to manage all SignalR traffic. Once a device drops an event on the event topic on SB:
- it's corresponding grain (based on deviceID) gets updated and the new status is stored inside the Grain's memory (some list).
- the SignalR grain gets notified on the change and does all the SignalR magic and updates all connected clients. In this case, the "SignalR Grain" pushes updates to the operator that just sent a Command to a devices (or all devices or a subgroup of devices).
This blogpost is to kick-off a new series of posts on IoT, Orleans and nice Azure features. Next time, more details!