servicefabriciothubdemo

所属分类:物联网
开发工具:C#
文件大小:4004KB
下载次数:0
上传日期:2016-10-06 13:51:59
上 传 者sh-1993
说明:  此示例演示如何使用服务结构、OWIN、物联网中心和事件中心创建简单的物联网应用程序。
(This sample demonstrates how to create a simple IoT application using Service Fabric, OWIN, IoT Hub and Event Hubs.)

文件列表:
AlertClient.lnk (1974, 2016-10-06)
AlertClient (0, 2016-10-06)
AlertClient\AlertClient.csproj (9234, 2016-10-06)
AlertClient\App.config (5457, 2016-10-06)
AlertClient\Controls (0, 2016-10-06)
AlertClient\Controls\Grouper.cs (23997, 2016-10-06)
AlertClient\Controls\HeaderPanel.Designer.cs (1204, 2016-10-06)
AlertClient\Controls\HeaderPanel.cs (6070, 2016-10-06)
AlertClient\Controls\HeaderPanel.resx (5695, 2016-10-06)
AlertClient\Controls\NumericTextBox.cs (3006, 2016-10-06)
AlertClient\Forms (0, 2016-10-06)
AlertClient\Forms\AboutForm.cs (13132, 2016-10-06)
AlertClient\Forms\AboutForm.designer.cs (10788, 2016-10-06)
AlertClient\Forms\AboutForm.resx (461495, 2016-10-06)
AlertClient\Forms\MainForm.Designer.cs (35658, 2016-10-06)
AlertClient\Forms\MainForm.cs (28980, 2016-10-06)
AlertClient\Forms\MainForm.resx (35845, 2016-10-06)
AlertClient\Helpers (0, 2016-10-06)
AlertClient\Helpers\EventProcessor.cs (5320, 2016-10-06)
AlertClient\Helpers\EventProcessorFactory.cs (2006, 2016-10-06)
AlertClient\Helpers\EventProcessorFactoryConfiguration.cs (1301, 2016-10-06)
AlertClient\Helpers\PropertyComparer.cs (2803, 2016-10-06)
AlertClient\Helpers\SortableBindingList.cs (3802, 2016-10-06)
AlertClient\Icons (0, 2016-10-06)
AlertClient\Icons\AzureLogo.ico (2462, 2016-10-06)
AlertClient\Icons\Tool.ico (16958, 2016-10-06)
AlertClient\Icons\WindowsAzureLogo.ico (4286, 2016-10-06)
AlertClient\Images (0, 2016-10-06)
AlertClient\Images\AzureLogo.png (1120, 2016-10-06)
AlertClient\Images\SmallDocument.png (438, 2016-10-06)
AlertClient\Images\SmallWorld.png (996, 2016-10-06)
AlertClient\Images\Warning.png (1778, 2016-10-06)
AlertClient\Images\WhiteLogo.png (1099, 2016-10-06)
AlertClient\Program.cs (1431, 2016-10-06)
AlertClient\Properties (0, 2016-10-06)
AlertClient\Properties\AssemblyInfo.cs (2276, 2016-10-06)
AlertClient\Properties\Resources.Designer.cs (5849, 2016-10-06)
... ...

--- services: service-fabric, event-hubs, iot-hub platforms: dotnet author: paolosalvatori --- # IoT Sample with Service Fabric and IoT Hub # This demo demonstrates how to build an IoT application for anomaly detection using Service Fabric, IoT Hubs, Event Hubs, OWIN and ASP.NET Web API.
# Architecture Design # The following picture shows the architecture design of the application.

![alt tag](https://raw.githubusercontent.com/paolosalvatori/servicefabriciothubdemo/master/Images/IoTHubArchitecture.png)
# Service Fabric Application # The Service Fabric application ingest events from the input Event Hub, processes sensor readings and generates an alert whenever a value outside of the tolerance range is received. The application is composed of three services: - **DeviceManagementWebService**: this is a stateless service hosting OWIN and exposing a REST management service. This service can be used to get or set metadata on devices actors. - **EventProcessorHostService**: this is a stateless service that creates an **EventProcessorHost** listener to receive messages from the IoT Hub. The **ProcessEventsAsync** method of the **EventProcessor** class uses an **ActorProxy** to send individual events to the proper actor, one for each device. - **DeviceActorService**: a stateful device actor is used to process incoming events at the device level. Each actor processes incoming sensor readings and generates an alert whenever the actual value is outside of the tolerance range identified by the **MinThreshold** and **MaxThreshold** properties. Alerts are sent to an output Event Hub. # Message Flow # 1. A client application built using Windows Forms is used to simulate a device management console. When you press the Start button, the client application creates the devices in the IoT Hub identity registry.
br/>![Client](https://raw.githubusercontent.com/paolosalvatori/servicefabriciothubdemo/master/Images/DeviceEmulator.png) 2. invokes the OWIN-hosted REST service exposed by the **DeviceManagementWebService** stateless service to initialize the device actors with the following metadata: - DeviceId - Name - MinThreshold - MaxThreshold - Model - Type - Manufacturer - City - Country 3. The **DeviceManagementWebService** stateless service activates the device actors and set their metadata, which is part of their persistent state. 4. For each device, the client application creates a separate task that simulates a distinct device sending messages to the input Event Hub. Each task acquires uses a different publisher endpoint. In particular, each task uses a SAS policy defined on the input Event Hub to acquire a SAS token to send events to its publisher endpoint. 5. The **EventProcessorHostService** uses an **EventProcessorHost** listener to receive messages from the input Event Hub. 6. The **ProcessEventsAsync** method of the **EventProcessor** class uses an **ActorProxy** to send individual events to the proper device actor. 7. Each actor processes incoming sensor readings and generates an alert whenever the actual value is outside of the tolerance range identified by the **MinThreshold** and **MaxThreshold** properties. Alerts are sent to an output Event Hub. 8. An **Alert Client** application built using Windows Forms uses **EventProcessorHost** listener to read alerts from the output Event Hub. 9. The **Alert Client** displays incoming events in a **DataGridView**. ![alt tag](https://raw.githubusercontent.com/paolosalvatori/servicefabriciothubdemo/master/Images/AlertClient.png) # Application Configuration # Make sure to replace the following placeholders in the project files below before deploying and testing the application on the local development Service Fabric cluster or before deploying the application to your Service Fabric cluster on Microsoft Azure. ## Placeholders ## This list contains the placeholders that need to be replaced before deploying and running the application: - **[IoT-Hub-Connection-String]**: contains the name of the **IoT Hub connection string**:
e.g. HostName=.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey= - **[IoT-Hub-Event-Hub-Compatible-Endpoint]**: contains the **Event Hub-Compatible Endpoint** of the **IoT Hub**:
e.g. Endpoint=sb://iothub-ns- - **[IoT-Hub-Event-Hub-Compatible-Name]**: contains the **Event Hub-Compatible Name** of the **IoT Hub** - **[Output-Event-Hub-Name];[Output-Event-Hub-Name];...**: contains a list of output **Event Hubs** defined in the output **Service Bus**. - **[Cluster-Name]**: the name of the **Service Fabric** cluster on Azure. - **[Cluster-Location]**: the location (e.g. eastus or westeurope) of the **Service Fabric** cluster on Azure. [Cluster-Location] - **[IoT-Hub-Storage-Account-Connection-String]**: contains the connection string of the **Storage Account** used by the **EventProcessorHost** to store partition lease information when reading data from the input **IoT Hub**. - **[IoT-Hub-Consumer-Group-Name]**: contains the name of the **Consumer Group** used by the **EventProcessorHost** to read data from the input **IoT Hub**. - **[Output-Event-Hub-Service-Bus-Namespace]**: contains the connection string of the **Service Bus** namespace containing the output **Event Hub** used by the application. - **[Output-Event-Storage-Account-Connection-String]**: contains the connection string of the **Storage Account** used by the **EventProcessorHost** to store partition lease information when reading data from the output **Event Hub**. - **[Output-Event-Consumer-Group-Name]**: contains the name of the **Consumer Group** used by the **EventProcessorHost** to read data from the output **Event Hub**. - **[Output-Event-Hub-Name]**: contains the name of the output **Event Hub**. ## Project Files ## **App.config** file in the **DeviceEmulator** project: ```xml ... ``` **App.config** file in the **AlertClient** project: ```xml ... ``` **ApplicationParameters\Local.xml** file in the **IoTDemo** project: ```xml ``` **ApplicationParameters\Cloud.xml** file in the **IoTDemo** project: ```xml ``` **ApplicationManifest.xml** file in the **IoTDemo** project: ```xml
```

近期下载者

相关文件


收藏者