I try to receive messages from Devices with the "EventHubReceiver" (Device2Cloud). Each device should have it's own, single receiver.
It isn't a problem to create one single EventHubReceiver (per Partition) for all devices:
string iotHubconnectionString = CloudConfigurationManager.GetSetting("Microsoft.IotHub.ConnectionStringPayed");
string iotHubD2cEndpoint = "messages/events";
EventHubClient eventHubClient = EventHubClient.CreateFromConnectionString(iotHubconnectionString, iotHubD2cEndpoint);
EventHubRuntimeInformation runtimeInformation = eventHubClient.GetRuntimeInformation();
If I then want to receive messages from the clients I do the following steps:
EventHubReceiver eventHubReceiver = eventHubClient2.GetDefaultConsumerGroup().CreateReceiver(partition); //Get the partitions via the runtimeInformation: string[] partitions = runtimeInformation.PartitionIds;
var incommingMessage = eventHubReceiver.ReceiveAsync(); //Wait here for incomming messages
That works all right, but all messages from all "Devices" arrive then at this one "EventHubReceiver". I would like to have multiple receiver, that only receive messages from a single device.
I tried to change the following codeline:
string iotHubD2cEndpoint = "messages/events";
to
string iotHubD2cEndpoint = "devices/{deviceID}/messages/events";
but that doesn't work all right. I get the following error:
The link address 'devices/secondDevice/messages/events/$management' did not match any of the expected formats. Supported formats: '/$cbs', '/devices/{deviceid}/messages/events', '/devices/{deviceid}/messages/deviceBound', '/messages/deviceBound', '/messages/serviceBound/feedback', '/messages/events/*'.
So the problem is that I get 'devices/secondDevice/messages/events/$management'
insted of 'devices/secondDevice/messages/events/'
I don't know, whether it is just not possible to create a single EventHubReceiver for each Device or I've got a error in the code or thinking.