5

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

感激地收到任何帮助

4

4 回答 4

10

你想用MessageQueue.ReceiveById吗?

于 2009-01-20T23:01:44.820 回答
2

你可以试试QueueExplorer

于 2009-01-20T22:45:22.890 回答
0

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

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

于 2009-01-20T23:05:46.123 回答
0
    // 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);
        }
    }
于 2020-11-12T14:59:20.917 回答