如何通过微软消息队列向不同的ip发送消息

时间:2014-01-31 16:16:22

标签: c# asp.net-mvc-4 message-queue

我正在研究基于Intranet的应用程序(我大学的访客管理系统),消息通过消息队列发送和接收,我想发送消息给我在下拉菜单中选择的特定部门,如化学部门只能查看其访客或IT部门只能查看其访客..

我的系统是一个中央服务器,几个客户端通过IP地址连接到同一网络,在后端我已经定义了部门的IP地址,以便向特定的ip发送消息但所有消息都发送到所有部门。

这是我的队列服务的代码

public class QueueService
{
    public void QueueMessage(HistoryModel hMsgs)
    {
        Message msg = new Message();
        msg.Body = hMsgs;
        msg.Recoverable = true;
        //msg.Formatter = new BinaryMessageFormatter();
        msg.Formatter = new XmlMessageFormatter();

        string machine = Environment.MachineName;

        IPHostEntry host;
        string localIP = "";
        host = Dns.GetHostEntry(Dns.GetHostName());
        foreach (IPAddress ip in host.AddressList)
        {
            if (ip.AddressFamily == AddressFamily.InterNetwork)
            {
                localIP = ip.ToString();
                break;
            }
        }

        string queuePath = "FormatName:Direct=TCP:" + localIP + @"\private$\WebsiteEmails";

        MessageQueue msgQ;

        InsureQueueExists(queuePath);

        msgQ = new MessageQueue(queuePath);
        //msgQ.Formatter = new BinaryMessageFormatter();
        msgQ.Formatter = new XmlMessageFormatter();

        msgQ.Send(msg);     // end Sending
    }

    public static void InsureQueueExists(string queuePath)
    {
        //if this queue doesn't exist we will create it
        if (!MessageQueue.Exists(queuePath))
            MessageQueue.Create(queuePath);
    }
}

}

访客表单的视图代码

<h3>Add History</h3>
                    </legend>
                    <div class="row">
                        <div class="col-lg-4">
                            <label class="control-label" for="VisitPurporse">Department<span class="messages">@Html.ValidationMessageFor(m => m.VisitPurporse)</span></label>
                            <div>
                                <select id="Department_Id" name="Department_Id" class="form-control">
                                    <option value="1">Chemistry</option>
                                    <option value="2">Computer Science</option>
                                    <option value="3">Information Technology</option>
                                </select>
                            </div>
                        </div>
                    </div>

请帮忙。如果我想将消息发送到我在下拉菜单中选择的特定部门,那将是什么情景

0 个答案:

没有答案