简体   繁体   中英

c# Web Api service call with no return value - async processing

I am looking to create a Web Api c# fire and forget service that I can post a payload to and immediately return a success or failure based on some initial checks, but then do the rest of the heavy processing asynchronously after the return 200 has been made.

What is the best approach for situations like this?

I am struggling to find a concrete example on the web to be honest.

Thanks Neil

I wouldn't call the best approach but one possible approach is using message queues .

Your flow would be:

  1. Call the RESTful API.
  2. The RESTful API resource enqueues a message and returns 200/OK if it could be done successfully.
  3. Some asynchronous worker (a different process than the Web API one) dequeues messages overtime and processes them. The whole process can be a Windows service (do you know Topshelf ?), a Windows Task Scheduler task...

If you're already in Azure, take a look at Service Bus , otherwise, you might want to learn more about a message queue server like RabbitMQ .

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