代码之家  ›  专栏  ›  技术社区  ›  spacemonkeys

删除单个消息MSMQ

  •  5
  • spacemonkeys  · 技术社区  · 16 年前

    是否可以从MSMQ消息队列中删除单个消息?我有一个Queue对象,一个通过窥视得到的消息(对象)和消息的ID,我可以看到删除(或清除)整个队列的方法,但我看不到单独删除消息的方法,我尝试在通过窥视找到消息后接收它,但我收到了“光标无效”的错误

    非常感谢您的帮助

    4 回复  |  直到 16 年前
        1
  •  10
  •   Abtin Forouzandeh    16 年前

    你想用 MessageQueue.ReceiveById ?

        2
  •  2
  •   Abtin Forouzandeh    16 年前

    你可以试试 QueueExplorer .

        3
  •  0
  •   Igal Serban    16 年前

    使用其中一个接收功能。取决于你的语言/技术(c,com,.net)。

    对于.net,它将是MessageQueue。ReceiveById方法。或者任何你认为合适的。取决于您要删除的消息(第一个、最后一个,使用游标或id)。

        4
  •  0
  •   Alexander Kunjukunju    4 年前
        // Language C#
        // Delete Message Button click handler.
        public void DeleteOneMessage()
        {
            // I created winforms application and added a reference to "System.Messaging"
            // Added one edit box name = queueNameTextBox
            // On Form_Load set queueNameTextBox.Text = @"private$\myQueueName"
            // Connect to the queue on the local computer.
            MessageQueue myQueue = new MessageQueue(queueNameTextBox.Text);
    
            // Set the formatter to indicate body contains an Order.
            myQueue.Formatter = new BinaryMessageFormatter();
    
            try
            {
                // Receive and format the message.
                object myMessage = myQueue.Receive();
                MessageBox.Show("One message removed from the queue.");
            }
            catch (MessageQueueException mqe)
            {
                MessageBox.Show(mqe.Message);
            }
            catch (InvalidOperationException e)
            {
                MessageBox.Show(e.Message);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }