4

I have used web services(WCF with asynchronous callback). Now I am learning Messaging Queues. When we can prefer a Message Queue over Web service

For Example: If I implemented an Asynchronous web service(WCF with Async callback or Asynchronous REST service), I can request for something and in meanwhile I can continue with other operations. So when we can prefer Message Queue over async web service?.

Santosh
  • 41
  • 4
  • 4
    They are very different. A web service mostly works in-memory so if there are, let's say, a 1000 requests to be processed by the server and the server crashes, all 1000 requests are lost. With a message queue, if the server crashes and then comes back to life, the messages will still be in the queue. There are many other differences too but that is one I can think of. Please note that the WCF has MSMQ as one of its bindings. – CodingYoshi Jun 21 '19 at 11:31
  • Okay. I understand. Yes there is a binding called netMSMQBinding in WCF but I have used only basicHTTPbinding. Because due to the reason like server crash only we will prefer MQ? Can you please provide me some other scenarios where we can use MQ's. – Santosh Jun 21 '19 at 12:03
  • When doing internal system communications you can use message queues to provide durable loosely coupled components, if you are providing or consuming external APIs you can use web APIs (REST/SOAP) and use message queues to manage the processing. Meybe this can help? https://docs.particular.net/nservicebus/architecture/principles – Sean Farmar Jun 22 '19 at 09:38

1 Answers1

4

There are numerous reasons for using Message Queues over asynchronous Web Services or REST communication patterns:

  1. Decouple senders from consumers: Services sending data are not directly invoking consumers for the data, which decouple services from each other. This makes it easier to evolve the architecture down the road.
  2. Replaying failed transmission: As a result of sending services having to directly invoke consuming services, failed transmissions of data can be tricky to handle. Message queues persist messages even if individual services go down, which allows services to begin reading messages of the queue once the service is back up.

  3. Asynchronous Protocol: While you might be able to make asynchronous HTTP calls, message queues are asynchronous at a protocol level which make them lighter weight and more efficient in architectures in which a large volume of small messages are being exchanged.

Also be aware of some common misunderstandings when deciding to use between RESTful communication patterns and message queues.