MSMQ - message queuing has not been installed on this computer

不羁的心 提交于 2019-12-30 01:58:49

问题


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;
        }

    }
}

回答1:


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.



回答2:


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.



来源:https://stackoverflow.com/questions/9798079/msmq-message-queuing-has-not-been-installed-on-this-computer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!