Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

.NET Core Simulator sample for Azure IoT Hub

The sample code is supplement to the blog post [Developing a .NET Core Simulator for Azure IoT Hub using VS for mac] The code provides a .NET Core based simulator for connecting to IoT Hub and performing the following operations:

  1. Send a message using a .NET Core simulator to Azure IoT Hub using AMQP as the protocol.
  2. Receive a message using a .NET Core consumer
  3. Send a command to a device and receive an acknowledgment from the device (coming soon).

The solution has been entirely developed using VS for Mac (preview) using macOS (10.12.3) but should be able to run on any .NET Core compatible IDE. The dot net standard assemblies using v1.6 and the dot net core version is 1.1.

Project structure

The solution contains the following projects:

  1. samples.iot.core: Contains core components, interfaces, base entity model to be used by the sample. It also contains some shared functionality such as Configuration handlers, token providers, connectivity modules.
  2. samples.iot.providers.sender: Sender factory implementation for sending messages to IoT Hub.
  3. samples.iot.simulator.sender: The .NET Core Console app that provides an interface to configure your IoT Hub instance and send messages.
  4. samples.iot.simulator.consumer: The .NET Core Console app that provides an interface to consume incoming messages from the Event Hub Compatible Azure IoT Hub endpoint.
  5. samples.iot.strategies.amqp: AMQP Lite strategy for IoT Hub. The sample follows a strategy patterns for the underlying modules so for example, the current implementation being used is AMQP Lite, if you want to switch the implementation to a different AMQP provider, simply create your strategy and inject that to the provider.
	//Using AMQP lite strategy to send the message
	IDeviceSendStrategy deviceSendStrategy = new DeviceSendAMQPLiteStrategy();
	// Send the message
	await new DeviceSenderFactory().GetSender().SendMessageAsync(messageAsBytes, deviceContext, deviceSendStrategy);
  1. samples.iot.simulator.contracts: Shared contracts between sender, receiver and consumer projects. The current sample leverages protobuf as the data interchange protocol and the the assembly is being used to provide the serialization and de-serialization.
	namespace samples.iot.simulator.contract
		public class VehicleStatus
			public Guid Id { get; set; }
			public int LockStatus { get; set; }
			public int TirePessure { get; set; }
			public int MilesRemaining { get; set; }
			public bool SportMode { get; set; }
			public int IgnitionStatus { get; set; }
			public int ParkStatus { get; set; }
			public int AlarmStatus { get; set; }
			public int AirBagStatus { get; set; }
  1. samples.iot.providers.receiver: Includes the implementation of the receiving commands from services and responding with acknowledgement. (Coming Soon)

How to run the sample

To run the sample, follow the steps below:

  1. Clone the repo and ensure you are able to compile the projects after restoring all nugget packages.

  2. The samples.iot.simulator.sender and samples.iot.simulator.consumer projects leverage a custom configuration model which leverages JSON objects. Edit the settings.json in the project for these projects to provide your IoT Hub and [Event Hub compatible endpoint] details respectively.


    			"name":"your iothub",
    			"connectionString":"your IoTHubHostName (e.g.",
    			"sasKey":"your device token",
    	  "deviceId":"your device Id"


    				"name":"your iothub",
    				"sasKey":"your serviceToken",
    		  "deviceId":"your device Id"
  3. Build the solution.

  4. Run the samples.iot.simulator.sender project, this should generate a VehicleStatus messages, encode it as a protobuf packet and then send to your IoT Hub.

  5. Run the samples.iot.simulator.consumer project, this should scan all partitions, find the message for the Device and then decode the protobuf message to show current Alarm status for the device.

Known Issues

  1. The samples.iot.simulator.consumer project uses a custom implementation of processing messages from the Event Hub compatible endpoint. It was done because the current [Event Hub Processor nuget package] was not working properly with .NET Core. The code will be updated to use an EventProcessor host implementation once the issue is fixed.
  2. The codebase is a sample and is provided AS-IS, it has not been tested for performance, fault tolerance, scalability, exception handling and instrumentation scenarios.


.NET Core Sample to perform operations on Azure IoT Hub







No releases published


No packages published