Monday, 15 June 2020

Azure Service Bus First In, First Out (FIFO)

Introduction

With Azure Service Bus, you get some great features but to get guaranteed FIFO (First-In, First-Out, i.e. ordered delivery), there was a lot of documentation to read through so I thought I'd show a quick example using a Topic and Subscriber.

Service Bus Message Sessions

To ensure FIFO, Service Bus requires that a Session is used which is fairly simple. The sender needs to set the SessionId property on the Message that it sends.

You need to enable message sessions, we will need to enable this when we create the subscription:



Sender:
This method below initialises a TopicClient using a connection string and topic name. It then creates a list of messages to send to the service bus topic and it sets the same SessionId on each one. If you don't specify the same SessionId, you'll find messages received in the wrong order.



Receiver:
The receiver, initialises a SubscriptionClient then calls the RegisterSessionHandle() method which registers a message handler and takes a SessionHandlerOptions parameter. This SessionHandlerOptions object requires that a exception message handler is specified which is called in case of an exception handling the message.



This handler references the ProcessMessageAsync() method which takes an IMessageSession, Message and CancellationToken:



The ProcessMessageException() method looks like this:



That's all you need to do to get this working. Let's test it out.


Testing

To test it out, I set up a simple console app which sends the messages to the topic, waits for them to be processed and then checks to make sure all received messages are in the correct order. See below:


13 comments:

  1. What an awesome written by you! I am too glad to read this kind of informative blog article. Thanks to sharing this with us, really thank you!!!!!!
    Dubai VPS Server

    ReplyDelete
  2. I am very enjoying to read your well-written article posts. It seems that you devote a great deal of hard work and time onto your own blog.Learn PMP Certification in Hyderabad 360DigiTMG

    ReplyDelete
  3. Need a Debt Loan To Pay Off Bills?
    Take control of your debt today
    Available Now Business Expansion Loan Offer?
    Do you need a loan to pay off Bills?
    Do you need a loan?
    Do you need Personal Loan?
    Business Expansion Loan?
    Business Start-up, Education,
    Debt Consolidation Loan
    Hard Money Loans
    Loan for any thing ?
    We offer loan at low interest rate of 3%
    Loan with no credit check,
    Email us: financialserviceoffer876@gmail.com
    Call or add us on what's app +918929509036

    ReplyDelete
  4. While using the printer on the off chance that it stalls out in the center of the work, it can raise the temper of the user. We have seen numerous user putting their inquiries dependent on ordinance printer in error state issue, for instance what do I do if my group printer is in error state?, how would I get my standard printer out of error state, etc. Consequently, to tackle every one of these inquiries we have the arrangement and it is referenced underneath.
    Printer in an error state canon

    ReplyDelete
  5. Useful post Thanks for sharing it that’s truly valuable knowledge about similar topic. Amazing. Have a more successful day. Amazing write-up always finds something interesting. english classes for kids

    ReplyDelete
  6. Useful posts, I really appreciate your writing skills and your hard work. You are providing such deep information, that's why I would love to see more blogs about this subject. I am inspired by you and I am also writing about the IELTS online coaching . Please review it.

    ReplyDelete
  7. What a fantastic post! This is so chock full of useful information I can't wait to dig deep and start utilizing the resources you have given me. your exuberance is refreshing

    you've outdone yourself this time

    This is probably the best, most concise step-by-step guide I've ever seen on how to build a successful blog. i am also writing blog about the  kindly review it personality development classes in Delhi .

    ReplyDelete
  8. Great Post Admin,
    Roku is a kind of streaming device that offers the most convenient way to watch TV. For any Quires feel free contact us.
    Activate Hulu Plus on Roku Device
    Activate Hulu On Smart TV

    ReplyDelete
  9. My name is Samuel, I was in love with my wife and we were married for eight years with a son his is Liam,I loved my wife so much she had access to all my bank account and even my cash app which my accountant agreed to and said it was a great idea, then it took my wife and my accountant two month to get hold of all my properties,all accounts but I had a cash app which they knew nothing about,I was thrown out of my own house was sleeping in a hotel for weeks she also took possession of my son could only see him once a week then I found out she was in love with my accountant all these while so I went online and I came across a private investigator who help me get all my properties and my accounts back even my company back how he did these I don’t know but I gave all the information he asked for and followed all his instructions and now I’m happy my life’s better now.
    Thanks to premiumhackservices@gmail.com
    I just said I should share my own story here
    Thank you

    ReplyDelete