Need to receive Azure Service Bus Messages on a .NET Framework 4.6.1 application

1k Views Asked by At

I Have an Azure Cloud Function that pushes messages to a queue under a Azure Service Bus namespace. The receiver for this queue is a .NET Framework 4.6.1 application which has the Service Bus SDK[Azure.Messaging.ServiceBus] installed. Problem is that the code sample references online are mostly for console applications which has Program.cs. My application has a Global.asax file, i believe, as the startup file.

So I referred the code from here. Placed it in Global.asax but not able to receive messages.

What has been tried is, I've created a console application on the same VM as the one which has the application mentioned above. Installed the SDK and pasted the listener code. It was able to receive messages from Service bus, which strikes off any possibilities of network misconfiguration. So most likely its the setup at .net 4.6.1 application level

Can anyone help with a sample service bus receiver/listener code?

1

There are 1 best solutions below

5
On
  1. Create a Service Bus in Azure.

enter image description here

  1. And create a Queue.

enter image description here

  1. And pushed some messages to the queue as per the link given.

enter image description here

enter image description here

For Queue_AccessKey string, copy the string from azure as shown below.

enter image description here

Use the Console application and use the below code in .Net 4.6.1 framework.

For this the NuGet "Microsoft.Azure.ServiceBus" version="5.2.0" targetFramework="net461” has to be installed in the project.

And the below namespace has to be used in the code. using Microsoft.Azure.ServiceBus;

connectionString = new ServiceBusConnectionStringBuilder(Queue_AccessKey);
qClient = new QueueClient(connectionString, ReceiveMode.ReceiveAndDelete, RetryPolicy.Default);    
var msgHandler = new MessageHandlerOptions(ListenerExceptionHandler)
      {
         MaxConcurrentCalls = 1,
         AutoComplete = false
      };    
qClient.RegisterMessageHandler(ReceiveMessageFromQueue, msgHandler);