8

現在、IPC を実現するために C# および .NET で MSMQ を使用しようとしています。私はそれがどのように機能するかを理解しようとしています.MSMQキューにアクセスするときのパス名とフォーマット名の違いについてかなり混乱しています. 次の投稿で同様の問題をいくつか見つけました。

  1. HTTP 経由の MSMQ 呼び出しが宛先キューに到達しない
  2. インターネット経由でアクセスできるように MSMQ サーバーをセットアップする方法
  3. それぞれの WCF バインディングを介して MSMQ over http を使用する方法は?

ただし、それらはすべて MSMQ と WCF を使用しているため、現時点では WCF を使用したくありません。

私が達成したいことは次のとおりです。

クライアント: httpを介してキューにデータを送信します。

サーバー: httpを介してキューからデータを受信します。

ここでの私のポイントは、サーバー、クライアント、およびキューのいずれかが潜在的に異なるコンピューターでホストされることを望んでいるということです。(今のところ、同じマシンですべてをテストしています)。

ここに、私が考えていることを示す次のコードがあります。

まず、キューを作成します。

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

クライアントコード:

次に、クライアント側に、メッセージを送信するためにユーザーがボタンを押したときに呼び出されるコールバック関数があります。

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

ここまではすべて正常に動作します。

サーバーコード:

次に、コールバック関数を呼び出してサーバー側のキューから 1 つのメッセージを同期的に読み取るボタンがあります。

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

私の (限られた) MSMQ の理解では、これでうまくいくはずです。ただし、呼び出すMessage msg = mq.Receive();と、次の例外が発生します。

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

そしてスタックトレース:

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

これをどのようにデバッグできるか、または私がやりたいことがそれらの手段で達成できるかどうか、誰かが考えを持っていますか?

4

1 に答える 1