

SERVICE BUS QUEUE FIFO UPDATE
Running the console app creates 400 messages on both subscriptions, 4 status update messages per 1 order.

Typical ScenarioĪ warehouse needs to track the progress of an order from when its first received to when it gets dispatched. Enabling sessions on the Azure Function places a lock on all messages that have the same session Id causing the locked messages to be consumed by that one function instance that placed the lock.

This feature for Azure Functions to use SB sessions only came GA as of mid 2019. Azure Functions need to have the IsSessionsEnabled property set to enabled on the SB input binding. Some examples of a session Id could be the account number, customer number, batch Id, etc. Messages sent onto the SB must set the context property SessionId to unique value from other non related messages. The property Requires Session must be enabled on the SB queues and topic subscriptions. To enforce message ordering several properties must be set. A more scalable option is to use sessions.This allows you to have multiple instances of a function executing giving you a higher message throughput. The only problem with this solution is it won’t scale very well. One option to enforce ordered delivery is to configure the Azure Function to spin up only one instance. This is represented in the sequence diagram below, where the function instance 1 took longer to update the same record in a database than instance 2. Typically when using Azure Functions to consume messages from a Service Bus (SB), the ordering is not guaranteed although the SB is First-In-First-Out (FIFO). This is due to competing consumers, where multiple instances of the function are competing for messages of the service bus.Īn example where out of ordering can happen is when a function instance takes longer to process a message than other instances therefore affecting the process ordering.
