5

Have been looking for a Message bus with publish/subscribe functionality. Found that AWS SQS does not support FIFO, so had to give up on it. Working with Azure Service bus, found that queues do support FIFO, but it seems like Topics do not support FIFO. And topics are what we need, with their pub-to-many-sub model :(

Is it just a setting I am missing? I tried sending 100 messages from my C# client, and the subscribers got the messages in the wrong order. Any tips would be appreciated. Thanks!

mattr
  • 181
  • 2
  • 10
  • Not familiar with Azure. But with WCF you can decorate your contract with: [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, )] Maybe there is a similiar thing for Azure? – David P Feb 24 '15 at 17:46
  • I published messages to the topic with data being messageId from 0 to 99. At the receiving end, the subscribers showed that they had received 93 before 91 etc. – mattr Feb 24 '15 at 18:10
  • http://stackoverflow.com/questions/7430036/how-to-gurantee-azure-queue-fifo/43137554#43137554 – Mohit Verma Mar 31 '17 at 09:46

3 Answers3

6

You can use session to get an Azure topic to provide FIFO ordering but that's not quite the same thing as guaranteeing the order in which messages are processed.

Sessions are not enough of a guarantee here. For example, if you are using PeekLock mode then a message that times out will return to the queue and be processed out of order. You can use ReceiveAndDelete mode to counter this behavior but that means you lose the transactional nature of message handling.

One of the reasons why documentation may be a little light on this area is that it isn't a common use case. Messaging is about decoupling though asynchronous communication and ordering guarantees create temporal coupling between applications.

Ideally you should design your payloads so ordering doesn't matter. If that fails, use a timestamp that allows you to discard messages received out of order.

Discussed in more detail here: Don’t assume message ordering in Azure Service Bus

Ben Morris
  • 585
  • 3
  • 6
  • I’ve asked a follow up question is your concern still valid https://stackoverflow.com/questions/69950471/does-azure-service-bus-session-guarantee-the-fifo-order?noredirect=1&lq=1. Why a message that times out and return to the queue will be processed out of order? Can you provide any reference to confirm it? – Michael Freidgeim Nov 13 '21 at 02:08
2

You should be able to achieve this by setting property SupportOrdering to true

    // Configure Topic Settings
    TopicDescription td = new TopicDescription("TestTopic");
    td.SupportOrdering = true;

    // Create a new Topic with custom settings
    string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");

    var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
    namespaceManager.CreateTopic(td);
Low Flying Pelican
  • 5,974
  • 1
  • 32
  • 43
  • 2
    I found this link which seems to say that SupportOrdering only works for one consumer. If thats the case, we are back to a Azure Service Bus queue, arent we? https://social.msdn.microsoft.com/Forums/windowsserver/en-US/cb32114e-17ba-4acd-84f3-51abb81d2195/does-service-bus-topics-guarantee-ordered-message-delivery?forum=servbus – mattr Feb 24 '15 at 22:09
  • yes... if that is the case you probably might want to use some other approach. But have you tested this out? – Low Flying Pelican Feb 24 '15 at 22:56
  • 1
    I did. And FIFO does seem to work with multiple consumers to the same topic. Thanks again! Bit odd that I couldnt find any real documentation from Microsoft on the SupportOrdering flag. – mattr Feb 25 '15 at 18:17
0

I know this is an older post - but it does appear that Azure Service Bus Topic Subscriptions now support sessions allowing for FIFO of messages within the session.

enter image description here

I hope this helps.

George M Ceaser Jr
  • 1,497
  • 3
  • 23
  • 52