简体   繁体   English

删除单个消息 MSMQ

[英]Delete Single Message MSMQ

Is it possible to delete a single message from a MSMQ message queue ?是否可以从 MSMQ 消息队列中删除单个消息? I have a Queue object, a message (object) that I have got to by peeking and the ID of the message, I can see a way of deleting (or purging) the entire queue, but I can't see a way to delete the message on it's own, I've tried receiving the message once I have found it by peeking, but I get the error that "the cursor is invalid"我有一个 Queue 对象,一个消息(对象),我必须通过偷看和消息的 ID,我可以看到删除(或清除)整个队列的方法,但是我看不到删除的方法消息本身,我尝试通过偷看找到消息后接收消息,但我收到“光标无效”的错误消息

Any help gratefully received感激地收到任何帮助

您是否尝试使用MessageQueue.ReceiveById

你可以试试QueueExplorer

Use one of the receive function.使用接收功能之一。 Depending on your language/technology ( c, com, .net ).取决于您的语言/技术(c、com、.net)。

For .net it will be the MessageQueue.ReceiveById Method.对于 .net,它将是 MessageQueue.ReceiveById 方法。 Or any that you find appropriate.或者任何你认为合适的。 Depending on the message you want to remover (first, last, using cursor or id ).根据您想要移除的消息(第一个,最后一个,使用 cursor 或 id )。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM