I am posting messages to an Azure Service Bus Topic. One of the custom properties will be named recipientId and contain a string.
I have a point of contention in the processing because I need to update a sequential number in a database row for that specific recipient. The update must be atomic along with other DB updates because I am not allowed to have missing numbers in the sequence.
However, I don't want multiple function instances trying to process data for the same recipientId at the same time and encountering DB deadlocks on the same row.
Is there a way to assign some kind of affinity to topic subscribers so I can guarantee messages for the same recipientId will always go to the same function instance?
In psuedo-code what I need is something like
int hashCode = message.CustomProperties["sender"].GetHashCode();
var function = Functions[hashCode % Functions.Count];
function(message);
Obviously I cannot do this because the Azure function doesn't know how many instances there are running, so it would need to be something supported by Azure.
Is this even possible?