Use System.Messaging.MessageQueue or WCF for MSMQ?

5 years ago, I developed a program that used MSMQ.

At that time, I used System.Messaging.MessageQueue and System.Messaging.MessageQueueTransaction to place items on msmq.

Currently, I see people using WCF, and I'm confused to use WCF.

First of all, most code examples show how to queue items using WCF rather than getting OFF, but more importantly: when I use the WCF / MSMQ solution, I need to create an additional project, namely the wcf service.

Creating a wcf service, of course, is not a problem, but I also need to install it when I create it.

So I'm wondering: why should I use wcf to put items in the queue, and not to solve with .Net objects?

Or am I mistaken that I assume that when I use scf I need an EXTRA application for delivery, namely a wcf application?

EDIT: Scneario is: we have a site where people can unsubscribe. Instead of directly hitting the database (to unsubscribe), we put the request to unsubscribe in the queue, and another service (Windows service or console application) will receive items from the queue and perform actions with the database.

+4
source share
4 answers

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

Your current solution has a website that puts the request in the queue, and a Windows service that receives the request from the queue, then gets into the database. This is perfectly acceptable if you know that you will always use MSMQ forever, Amen.

However, you can change it as follows:

  • Your Windows service now has the WCF service (no additional project is required here). The WCF service provides the Unsubscribe method (the method name describes a logical action, not how it is performed).
  • Your website now acts as a WCF client that references the service (no additional project is required here). Website code calls the Unsubscribe method.
  • You configure WCF bindings to use MSMQ.

If in the future you decide that MSMQ is not required or if you are thinking of a better way, you can simply change the WCF bindings to use something else, and the code will remain the same.

+5
source

I recently met a similar question. Personally, I do not want to write another application in WCF. The process is too complicated, and if you made a mistake in setting up the configuration or their combinations, you can spend hours trying to get out of Google. I just wrote a simple application that pulls itself out of the queue in a multi-threaded way and pushes it from the Internet. This may be redundant for you. There are simple examples to help you get started and run, like this .

+2
source

Perhaps think of it this way: MSMQ is a messaging resource, just like SQL Server is for storing relationship data. Applications of all kinds can use this service (.NET console, network, service, etc., and, of course, other products of MQ providers).

It happens that Microsoft has tightly integrated MSMQ into WCF, and demo projects show this. The problem with reading + writing to the queue is not a concern. Any type of project can read and write to MSMQ the same way.

+1
source

I don’t think you need a separate project for your WCF service - I think it depends on the nature of your application. For example, there is no reason why you cannot have WCF services in a web application, all in one project.

But to your question, WCF support for MSMQ is designed to provide a unified way of messaging for applications, whether through web services, traditional services, COM + (what is this?) Or priority.

If your turn is entirely in your application, I'm not sure if this is necessary.

If your application provides queues to other users for recording, then having a WCF service up front might make sense. This will protect your users from knowing which queue to write, etc. They just need to connect to the service to send a message. Therefore, I believe that this is very good and hides some implementation details from the user, which is good.

If you could provide more detailed information about the nature of your application, I can provide more detailed information.

+1
source

All Articles