Sessions

In Azure Service Bus, sessions are used to achieve a FIFO guarantee. In general, the service does not control the relationship between messages, so even if in most cases the order is preserved, it is not guaranteed. To put a message to a session, you have to leverage a SessionId property:

await client.SendAsync(new Message(Encoding.UTF8.GetBytes(message)) { SessionId = Guid.Empty.ToString()});

To handle a session on the receiver side, you have to use the RegisterSessionHandler method on a QueueClient instance:

var client = new QueueClient("<connection-string>", "<queue-name>");client.RegisterSessionHandler((session, message, ct) => Task.FromResult(new SessionHandler()), args => Task.CompletedTask);

Additionally, you will have to ...

Get Hands-On Azure for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.