DEV Community

Discussion on: Get your C# WebAPI controller to keep processing a request after returning 200 OK

Collapse
 
ryanobray profile image
RyanObray

While I think this is a neat solution, it could also be a really good illustration of where message queues are super useful. Receive the request, write a message to a queue, return a response, do the heavy processing asynchronously as the message is dequeued and processed. The nice thing in the message queue scenario is that if processing fails, it's pretty easy to retry by pushing the message back into the active queue from dead letter. In this example if "DoProcessing" fails, it'd probably have to be more hands on to try it again. Definitely has some potentially helpful uses though. Thanks for sharing.

Collapse
 
deanashton profile image
Dean Ashton

Hi Ryan, thanks for your message. In this part of the system we had a pipeline that executed small tasks after a main process had finished executing to customise the results - and one task we needed to execute was really long running and it wasn't necessary to wait for it to finish (it produces a CSV file) to complete the pipeline. We definitely prefer to use message queues using NServiceBus and RabbitMQ in other parts of the system, for the reason you outlined.