Receiving only one message from Azure Service Bus

Some time ago I got a question from Eto: “How would I go about this if I just want to receive one message only?” And I started thinking… is it possible in .Net Core?

I used the newest Microsoft.Azure.ServiceBus package, that is dedicated for .Net Core, but there is no method to receive only one message. So I used regular RegisterMessageHandler with a twist:

As you can see it is a standard approach, but after successfully processed message, I close queueClient. This works and it receives only one message, but it also gives an error.

I wasn’t fully satisfied with the solution, so I asked a question on StackOverflow:

After a few hours, I got an answer, that it is possible and I should just… use different package!

Using the old package

So far I didn’t manage to use old package in .NetCore project. So in order to install package WindowsAzure.ServiceBus, you need to have project referencing full framework.

And here is the code:

So that’s it and it works, but sadly not in .Net Core. However, I’ll keep this post up to date when such thing will be possible.

3 thoughts on “Receiving only one message from Azure Service Bus

    1. I cannot agree. It is a way to solve a problem, but you’re right that it will only work in .net core. More and more projects runs on .net core, so I cannot say it’s a flaw.
      However, getting back to the solution, I think there is a better way to solve it. Azure Service Bus has REST API and it might be the right path for this problem.

Leave a Reply to DC Cancel reply

Your email address will not be published. Required fields are marked *