Skip Navigation LinksAzure Developers Guide > Azure Service Bus > Brokered Messaging > Brokered Messaging Features & Patterns > Message Sessions Example > Sending Messages using Sessions

Training Courses

All course material is in English, and courses are delivered in English. Feel free to contact me for further information.

Sending Messages using Sessions

The tag reader console application can now be modified to create a unique order ID for the RFID tag reads in the order and set the SessionId property of the messages accordingly.


// Create a unique OrderId

string orderId = Guid.NewGuid().ToString();

Console.WriteLine("OrderId: {0}", orderId);


while (position < 10)


    // Create a new brokered message from the order item RFID tag.

    BrokeredMessage tagRead = new BrokeredMessage(orderItems[position]);


    // Set the SessionId of the message to the OrderId

    tagRead.SessionId = orderId;


    // Set the Message Id to the ID of the RFID tag.

    tagRead.MessageId = orderItems[position].TagId;


    // Send the message


    Console.WriteLine("Sent: {0}", orderItems[position].Product);


    // Randomly cause a duplicate message to be sent.

    if (random.NextDouble() > 0.4) position++;







Setting the SessionId property is a requirement for sending messages to a queue that requires sessions, and the value used for SessionId must be unique amongst all active sessions.

Speaking Engagements