Azure-iot-sdk-csharp: "Message" class belongs to Microsoft.Azure.Devices.Client is not having 'SessionId' concept

Created on 24 Sep 2019  路  9Comments  路  Source: Azure/azure-iot-sdk-csharp

Hi @alrod,
Below is the sample , i am using for sending messages to topic-subscription.
may i know how to proceed with this problem?

static DeviceClient deviceClient;
var commandMessage = new Message("test");
commandMessage.Properties.Add("Component", "rs-dev"); // qa
commandMessage.Properties.Add("Channel", "cloud.temperature");
commandMessage.Properties.Add("Source", "Source");
await deviceClient.SendEventAsync(commandMessage);

i am using IOT Hub endpoints and MessageRouting to forward messages from device to required topic

here "Message" class belongs to Microsoft.Azure.Devices.Client so i am unable to keep "SessionId" for this "Message" class.

even i keep below statement to keep "SessionId" for message, session concept is not working after reaching this message to topic
commandMessage.Properties.Add("SessionId", "500");

could you please let me know how to apply "SessionId" to above scenario?

IoTSDK enhancement

Most helpful comment

@prmathur-microsoft
I faced with the same problem. I am using following path for device messages: Device -> IoT Hub -> Service Bus Topic -> Azure Function
I would like to use Microsoft Azure Service Bus sessions in Azure Function. Service bus demands the system property SessionId in the message be non empty.

When I am sending a message from a device through IoT Hub and defining a new property with the name SessionId, it comes to Custom properties of a brokered message in the ServiceBus. As the result Service Bus Topic is rejecting the message.

Is there any workaround or recommendations how it can be fixed.

As @appalaraju have proposed it will be nice to have such property directly in the Microsoft.Azure.Devices.Client.Message and corresponding support in the IoT Hub

Thanks
Best regards
Volodymyr

All 9 comments

Could you define what does this session id represent to you? Session id can be present on various levels eg protocol, iothub, transport etc. Which Session ID do you refer to ?

@prmathur-microsoft ,

Here i am referring "SessionID" for the messages coming from hardware devices.

i am referring below kind of SessionId for the message

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.servicebus.message.sessionid?view=azure-dotnet

The above link has "SessionId" for the Message class belongs to Microsoft.Azure.ServiceBus so topic-subscription receives the message from IOT Hub and can able to filter message based on 'SessionId" available inside the Message class so i want same kind of behavior the "Message" class belongs to Microsoft.Azure.Devices.Client

This SessionId enables uniqueness of each message coming from device so if "SessionId" is set at message level then topic-subscription or queue can use this 'SessionId" as grouping filter to maintain ordering of the messages coming from the same device.

i am not sure which level this Session ID refer to.

please look into below reference links

https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-sessions

https://docs.azure.cn/zh-cn/dotnet/api/microsoft.azure.servicebus.message.sessionid?view=azure-dotnet

https://www.codeguru.com/columns/experts/advanced-azure-queuing-with-the-sessions-and-the-service-bus.htm

Thanks,
Raju

@prmathur-microsoft
I faced with the same problem. I am using following path for device messages: Device -> IoT Hub -> Service Bus Topic -> Azure Function
I would like to use Microsoft Azure Service Bus sessions in Azure Function. Service bus demands the system property SessionId in the message be non empty.

When I am sending a message from a device through IoT Hub and defining a new property with the name SessionId, it comes to Custom properties of a brokered message in the ServiceBus. As the result Service Bus Topic is rejecting the message.

Is there any workaround or recommendations how it can be fixed.

As @appalaraju have proposed it will be nice to have such property directly in the Microsoft.Azure.Devices.Client.Message and corresponding support in the IoT Hub

Thanks
Best regards
Volodymyr

I just found, that there is a possibility to assign a value to sys.sessionId property in azure service bus topic subscription rule.
Just define following SqlRuleAction: set sys.sessionId="iothub-connection-device-id"
But I also found, that it does not work with my already existed topics, I had to create a new one.

Thanks for the feedback. Please vote on this User voice item and it can also be used for tracking our plans.

Closing this issue because @VDanylevskyi found the solution

@prmathur-microsoft, @appalaraju, @VDanylevskyi, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey

I just found, that there is a possibility to assign a value to sys.sessionId property in azure service bus topic subscription rule.
Just define following SqlRuleAction: set sys.sessionId="iothub-connection-device-id"
But I also found, that it does not work with my already existed topics, I had to create a new one.

@az-iot-builder-01, @VDanylevskyi , The option 'SqlRuleAction: set sys.sessionId="iothub-connection-device-id"' u suggested is good when we want to filter data based on device id but there are scenarios like from same device, we need to differentiate messages based on some kind of filter ( ex : RequestId is part of a message. same request id will be there in multiple messages coming from same device so in cloud, we need process messages by keeping requestId as session filter ) so how can we achieve this scenario?

Was this page helpful?
0 / 5 - 0 ratings