简体   繁体   中英

Implementing an Azure Service Bus listener application

I'm developing ASP.NET Web API services and placing these onto an Azure Service Bus queue to be processed. The Web API services are hosted on Azure.

I need to implement an application that listens for these messages and processes them when they are received.

I'd like this to be hosted on Azure but not sure of the best way to approach this.

  • Can you implement such a listener service and host it on Azure?
  • What is the best way to approach implementing such an application / service?

There are several things you can do. You could use ASB's OnMessage API which allows you to register your callback and handle incoming messages with concurrency and auto-completion.

On Azure you have several options: Cloud Services (worker roles), Azure Web Jobs , Azure Functions (if your processing is fast, otherwise I'd not recommend it), Service Fabric (might be a bit of an overkill if system is small), and plain VMs if needs to be.

Warning about functions - if you do intense work, Functions are not ideal as you'll pay for time/memory you execute.

A couple options for workers that listen to a queue are:

  1. Functions
  2. Web Jobs

You can see an example of using a Function here: https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-an-event-processing-function .

An example of using Web Jobs is here: https://docs.microsoft.com/en-us/azure/app-service-web/websites-dotnet-webjobs-sdk-service-bus .

Both allow you to create background jobs that consume messages from a queue. Both support Storage and Service Bus queues. The main difference is that Web Jobs require an App Service Plan with some amount of instances, while Functions can run on a Dynamic plan, which scales completely automatically.

You should note that Functions are not meant for really long-running jobs (more than 5-15 minutes), though neither are Web Jobs.

为什么不尝试在docker中运行linux进程(守护进程)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM