Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use System.Messaging.MessageQueue or WCF for MSMQ?

Tags:

c#

.net

wcf

msmq

5 years ago i've developed a program which used MSMQ.

Back then, i used the System.Messaging.MessageQueue and the System.Messaging.MessageQueueTransaction to put items on the msmq.

Nowadays i see people using WCF, and i'm confused wether to use WCF.

First of all most of the code examples only show how to put items ON the queue using WCF, and not get the OFF, but more important: when i use the WCF/MSMQ solution, i have to create an extra project, namely the wcf service.

Creating a wcf service of course is not the problem, but i also have to install it on production.

So i am wondering: why should i use wcf to put items on the queue, and not the solution with the .Net objects?

Or am i incorrect that i assume that when i use scf, that i need an EXTRA app to deliver, namely the wcf app?

EDIT: The scneario is this: we have a website where people can unsubscribe. In stead of hitting the database directly (to unsubscribe) we put the unsubscribe request on a queue and another service (windows service or console app) will get the items from the queue and do the database actions

like image 998
Michel Avatar asked Jan 18 '23 23:01

Michel


2 Answers

Using WCF to wrap MSMQ means that you are abstracting away the transmission mechanism, which allows you to change it later if you want.

Your current solution has a web site that puts a request in the queue, and a windows service that gets the request from the queue then hits the database. That is perfectly acceptable if you know that you will always use MSMQ for ever and ever, Amen.

However, you could change it as follows:

  • Your windows service now hosts a WCF service (no extra project required here). The WCF service exposes an Unsubscribe method (the method name describes the logical action, not how it's accomplished).
  • Your web site now acts as a WCF client that references the service (no extra project required here). The web site code calls the Unsubscribe method.
  • You configure the WCF bindings to use MSMQ.

If in future you decide that MSMQ is unnecessary, or you think of a better way, you can just change the WCF bindings to use something else, and the code will remain the same.

like image 187
Christian Hayter Avatar answered Jan 28 '23 07:01

Christian Hayter


Been through a similar question myself recently. Personally, I don't ever want to write another application in WCF. Its overly complex, and if you get a config setting wrong, or combinations thereof, you can spend hours trying to google your way out of it. I just wrote a simple app that pulls from the queue in a multithreaded fashion, and pushes to it from the web. That may be overkill for you. There are simple examples out there that will get you up and running, like this.

like image 26
Trent Avatar answered Jan 28 '23 08:01

Trent