使用MSMQ通过HTTP。如何解决队列? [英] Using MSMQ over HTTP. How to address the queue?

查看:565
本文介绍了使用MSMQ通过HTTP。如何解决队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在尝试使用MSMQ用C#和.NET,以达到IPC。 我想了解它是如何工作的,我很困惑的<一个href="http://blogs.msdn.com/b/johnbreakwell/archive/2009/02/26/difference-between-path-name-and-format-name-when-accessing-msmq-queues.aspx">differences当访问MSMQ队列的路径名和格式名之间。 我已经发现了一些类似的问题在下面的文章:

  1. <一个href="http://stackoverflow.com/questions/9488010/msmq-calls-over-http-not-reaching-destination-queue">MSMQ通过HTTP调用没有到达目标队列
  2. <一个href="http://stackoverflow.com/questions/19156136/how-to-setup-msmq-server-so-that-it-can-be-accessed-over-the-internet">How设置MSMQ服务器,这样就可以通过Internet
  3. 访问
  4. <一个href="http://stackoverflow.com/questions/4499091/how-to-use-msmq-over-http-through-the-respective-wcf-binding">How使用MSMQ HTTP上通过相应的WCF绑定?

不过,他们都使用MSMQ和WCF,我不希望使用WCF现在。

我想实现的是以下内容:

客户端:将数据发送到队列中通过的 HTTP

服务器:从队列中通过接收数据的 HTTP

在这里我想说的是,我想,无论是的服务器,客户端和队列的潜在不同的计算机上托管。 (现在我测试都在同一台机器)。

在这里,我有以下的code,这说明什么,我心里有:

首先,我创建队列:

 如果(System.Messaging.MessageQueue.Exists(@\私人$ \ SimplestExamplePrivateQueue。)!;
    System.Messaging.MessageQueue.Create(@\私人$ \ SimplestExamplePrivateQueue。);
 

客户端code:

然后,在客户端,我有被调用,当用户$ P $,以发送邮件psses一个按钮的回调函数。

 私人无效的button1_Click(对象发件人,发送System.EventArgs)
{
    尝试
    {
        //创建队列的连接
        System.Messaging.MessageQueue MQ =新System.Messaging.MessageQueue(@"FormatName:Direct=http://localhost/msmq/Private$/SimplestExamplePrivateQueue");

        //创建一个指向对象发送
        点myPoint =新的点(Convert.ToInt32(textBox2.Text),Convert.ToInt32(textBox3.Text));

        //发送对象
        mq.Send(myPoint);
    }

    //抓住这标志着所有类型的错误的异常
    //从消息队列子系统。报告错误
        //给用户。
    赶上(System.Messaging.MessageQueueException MQX)
    {
        的MessageBox.show(mqx.Message);
    }
 

一切,直到在这里工作得很好。

服务器code:

然后,我有一个按钮,它调用回调函数同步地从队列中读取一个消息在服务器端:

 私人无效的button1_Click(对象发件人,EventArgs的)
{
    尝试
    {
        //创建队列的连接
        变种MQ =新MessageQueue(@直接= HTTP://本地主机/ MSMQ /私人$ / SimplestExamplePrivateQueue);

        //设置队列的格式化脱code Point对象
        mq.Formatter =新给XMLMessageFormatter(新[] {typeof运算(点)});

        //同步接收消息
        消息味精= mq.Receive();

        //转换接收到的信息提出异议,我们认为被送往
        VAR PT =(点)msg.Body;

        //显示它给用户
        的MessageBox.show(pt.ToString(),接收点);
    }

    //报告任何异常给用户。超时会造成这样的
    //异常
    赶上(例外X)
    {
        的MessageBox.show(x.Message);
    }
}
 

在MSMQ我的(有限)的理解,这应该工作。然而,当我打电话信息味精= mq.Receive(); 我得到以下异常:

 指定的格式名称不支持请求的操作。例如,直接队列格式名不能被删除。
 

和堆栈跟踪:

 在System.Messaging.MessageQueue.MQCacheableInfo.get_ReadHandle()
   在System.Messaging.MessageQueue.StaleSafeReceiveMessage(UInt32的超时的Int32行动,MQPROPS性能,NativeOverlapped *重叠,ReceiveCallback receiveCallback,CursorHandle cursorHandle,IntPtr的交易)
   在System.Messaging.MessageQueue.ReceiveCurrent(时间跨度超时的Int32行动,CursorHandle光标,MessagePropertyFilter过滤器,MessageQueueTransaction internalTransaction,MessageQueueTransactionType TRANSACTIONTYPE)
   在System.Messaging.MessageQueue.Receive()
   在InternetQueueingRecipient.Form1.button1_Click(对象发件人,EventArgs e)在c:\Users\felipedalcin\Documents\MSMQ\MSMQandNET\InternetQueuing\InternetQueueingRecipient\Form1.cs:line 85
 

有没有人有我怎么能调试这还是一个想法,即使是我想做的事情是可以实现的那些手段?

解决方案

您无法通过HTTP接收消息。

<一href="http://blogs.msdn.com/b/johnbreakwell/archive/2008/06/09/msmq-over-http-is-a-push-only-technology.aspx"相对=nofollow>

I'm currently trying to use MSMQ with C# and .NET in order to achieve IPC. I am trying to understand how it works, and I'm quite confused about the differences between Path name and Format name when accessing MSMQ queues. I've found some similar issues in the following posts:

  1. MSMQ calls over HTTP not reaching destination queue
  2. How to setup MSMQ server so that it can be accessed over the Internet
  3. How to use MSMQ over http through the respective WCF binding?

However, they're all using MSMQ and WCF, and I don't want to use WCF for now.

What I want to achieve is the following:

Client: Sends data to the queue through http.

Server: Receives data from the queue through http.

My point here is that I want that either server, client and the queue to be hosted in potentially different computers. (For now I'm testing everything in the same machine).

Here I have the following code, which demonstrates what I have in mind:

First, I create the queue:

if(!System.Messaging.MessageQueue.Exists(@".\Private$\SimplestExamplePrivateQueue");
    System.Messaging.MessageQueue.Create(@".\Private$\SimplestExamplePrivateQueue");

Client code:

Then, at the client side, I have a callback function which is invoked when the user presses a button in order to send a message.

private void button1_Click(object sender, System.EventArgs e)
{
    try
    {           
        // Create a connection to the queue
        System.Messaging.MessageQueue mq = new System.Messaging.MessageQueue(@"FormatName:Direct=http://localhost/msmq/Private$/SimplestExamplePrivateQueue");

        // Create a point object to send
        Point myPoint = new Point (Convert.ToInt32(textBox2.Text), Convert.ToInt32(textBox3.Text)) ;

        // Send object 
        mq.Send (myPoint) ;
    }

    // Catch the exception that signals all types of error
    // from the message queueing subsystem. Report error
        // to the user. 
    catch (System.Messaging.MessageQueueException mqx)
    {
        MessageBox.Show (mqx.Message) ;
    }

Everything until here works fine.

Server code:

Then, I have a button which invokes a callback function to synchronously read one message from the queue at the server side:

private void button1_Click(object sender, EventArgs e)
{
    try
    {
        // Create a connection to the queue
        var mq = new MessageQueue(@"Direct=http://localhost/msmq/Private$/SimplestExamplePrivateQueue");

        // Set the queue's formatter to decode Point objects
        mq.Formatter = new XmlMessageFormatter(new[] {typeof (Point)});

        // Receive message synchronously
        Message msg = mq.Receive();

        // Convert received message to object that we think was sent
        var pt = (Point) msg.Body;

        // Display it to the user
        MessageBox.Show(pt.ToString(), "Received Point");
    }

    // Report any exceptions to the user. A timeout would cause such
    // an exception
    catch (Exception x)
    {
        MessageBox.Show(x.Message);
    }
}

In my (limited) understanding of MSMQ, this should work. However, when I call Message msg = mq.Receive(); I get the following exception:

The specified format name does not support the requested operation. For example, a direct queue format name cannot be deleted.

And the Stack Trace:

at System.Messaging.MessageQueue.MQCacheableInfo.get_ReadHandle()
   at System.Messaging.MessageQueue.StaleSafeReceiveMessage(UInt32 timeout, Int32 action, MQPROPS properties, NativeOverlapped* overlapped, ReceiveCallback receiveCallback, CursorHandle cursorHandle, IntPtr transaction)
   at System.Messaging.MessageQueue.ReceiveCurrent(TimeSpan timeout, Int32 action, CursorHandle cursor, MessagePropertyFilter filter, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
   at System.Messaging.MessageQueue.Receive()
   at InternetQueueingRecipient.Form1.button1_Click(Object sender, EventArgs e) in c:\Users\felipedalcin\Documents\MSMQ\MSMQandNET\InternetQueuing\InternetQueueingRecipient\Form1.cs:line 85

Does anyone have an idea of how I could debug this or even if what I want to do is achievable by those means?

解决方案

You cannot receive messages over HTTP.

Explanation

这篇关于使用MSMQ通过HTTP。如何解决队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆