MSMQ - message queuing has not been installed on this computer
Asked Answered
M

2

17

I have written a sample application to write to a public and private queues that are on dev server. I don't have the message queue installed on my local machine.

I am getting error: message queuing has not been installed on this computer.

Error is on this line:

MessageQueue.Exists(queueName)

Here is the full test code, all commented and not commented private and public queues are resulting in the same error. What am i doing wrong here?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Messaging;

namespace MsmqTest
{
    public partial class Form1 : Form
    {
        //@"DIRECT=OS:devbox01\PRIVATE$\PrivateQueueDev";
        //@"DIRECT=TCP:192.168.6.102\PRIVATE$\PrivateQueueDev";
        private const string QueueName = @"DIRECT=TCP:192.168.6.102\PRIVATE$\PrivateQueueDev";


        //@"DIRECT=OS:devbox01\PublicQueueDev";
        //@"DIRECT=TCP:192.168.6.102\PublicQueueDev";
        private const string QueueNamePublic = @"DIRECT=TCP:192.168.6.102\PublicQueueDev";

        public Form1()
        {
            InitializeComponent();
        }

        private void Write_Click(object sender, EventArgs e)
        {
            MessageQueue msgQ;
            string msgText = String.Format("Message: {0}", DateTime.Now);
            try
            {
                msgQ = GetQ(QueueNamePublic);
                msgQ.Send(msgText);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        private void Read_Click(object sender, EventArgs e)
        {

        }

        private MessageQueue GetQ(string queueName)
        {
            MessageQueue msgQ;

            if(!MessageQueue.Exists(queueName))
            {
                try
                {
                    msgQ = MessageQueue.Create(queueName);
                }
                catch (Exception ex)
                {
                    throw new Exception("Error creating queue", ex);
                }
            }
            else
            {
                try
                {
                    msgQ = new MessageQueue(queueName);
                }
                catch (Exception ex)
                {
                    throw new Exception("Error getting queue", ex);
                }
            }
            return msgQ;
        }

    }
}
Miramirabeau answered 21/3, 2012 at 3:5 Comment(0)
S
24

You need to install MSMQ on ALL machines which want to participate in the transmission and reception of messages. That includes sending machines such as your local machine in this instance.

The reason for this is because of the store-and-forward messaging pattern that MSMQ uses.

http://en.wikipedia.org/wiki/Store_and_forward

What is actually happening when you "send" a message to your server is:

  1. The local queue manager writes the message to a local temporary queue.
  2. The local queue manager connects to the remote queue manager.
  3. The message is transmitted.
  4. The remote queue manager writes the message to the remote queue.
Squier answered 21/3, 2012 at 8:9 Comment(7)
So what are my alternatives here? I don't want to install it on users machine then will be sending the message. Can i use WCF? Could you please point me to some sample code that can help?Miramirabeau
There is no alternative if you want to use MSMQ. I don't think enabling it on a users machine should be an issue. It's part of windows.Squier
We have about 15 to 20 users that will need this enabled. What can i use instead of MSMQ? Basically, clients will be sending an id and then listner will need to perform some tasks per that id. It needs to be a queue style process, first in first out.Miramirabeau
All the queuing alternatives I know of (RabbitMQ, and ZeroMQ) rely on installations on both ends. Queuing guarantees delivery of each message, exactly once. In order to achieve that you need a client on both ends. If you don't have this requirement then you don't really need to use queuing, and you could use a web service call or something similar.Squier
How to enable MSMQ (on 64 bit machines): jprog.com/wiki/…Dulia
@Dulia You can enable msmq on 64 bit the same way as 32 bit.Squier
This is a helpful answer. We have 250 desktop users taking install of a package I created that are now going to need MSMQ installed locally, and there do not appear to be many programmatic solutions for doing that. Genius, Microsoft.Beaker
A
6

Refactor out the MSMQ logic to a service and call the service from your code, passing the message. That way you only have to install MSMQ on the server.

Aesthete answered 5/2, 2014 at 23:42 Comment(1)
Good idea; I'm going with this.Beaker

© 2022 - 2024 — McMap. All rights reserved.