MSMQ - 快速生产者/慢速消费者

发布于 2024-08-21 00:06:08 字数 585 浏览 13 评论 0原文

我在消息传递(使用 MSMQ)方面遇到问题,这是快速生产者/慢速消费者的变体。有没有办法获取私有 MSMQ 队列中未使用的未使用消息计数?我想用它来限制生产者。

我想在 MSMQ 中使用信号量范例,其中生产者应用程序仅在未完成的消息计数小于指定数量时才发送消息。

本质上,我想做类似以下的事情

///Producer pseudo-code 
public void SendMessage(Message message, int totalMessagesSentCounter)
{
    if (totalMessagesSentCounter % 1000 == 0)
    {
        while (outgoingQueue.GetMessageCount() > X)  ///Is this possible?
        {
            Sleep(Y milliseconds);
        }
    }
    outgoingQueue.Send(Message);
    totalMessagesSentCounter++;
}

我的配置:Win XP/2003 with MSMQ 3.0

I have a problem with messaging (with MSMQ) which is a variation of fast producer/slow consumer. Is there a way to get outstanding unconsumed message count in a private MSMQ queue? I would like to use that to throttle the producer.

I would like to use a semaphore paradigm with MSMQ where the producer application will only send messages if the outstanding message count is less than a specified number.

Essentially, I would like to do something like the following

///Producer pseudo-code 
public void SendMessage(Message message, int totalMessagesSentCounter)
{
    if (totalMessagesSentCounter % 1000 == 0)
    {
        while (outgoingQueue.GetMessageCount() > X)  ///Is this possible?
        {
            Sleep(Y milliseconds);
        }
    }
    outgoingQueue.Send(Message);
    totalMessagesSentCounter++;
}

My configuration : Win XP/2003 with MSMQ 3.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

安稳善良 2024-08-28 00:06:08

我没有使用过 MSMQ 本身,但我确实有一个我发现有用的秘诀。

您有两个队列,而不是单个队列 - 每个方向一个。

“生产者”使用来自消费者的队列中的项目,并向消费者发送一条新消息。消费者每次消费时,都会在队列中放入一条新消息给生产者。

因此,通过这种方式,“令牌”提供从消费者到生产者的反馈,将生产者限制在消费者的速度。

如果合适的话,一个技巧是简单地返回消息,而不是每次都进行新的分配。如果它是单进程且消息数据很大并且大小固定,那么这本身就可以成为采用此设计的强大驱动力。

I have not used MSMQ itself, but I do have a recipe that I've found useful.

Rather than a single queue, you have two queues - one in each direction.

The 'producer' consumes an item from the queue that comes from the consumer, and sends a new message out to the consumer. Each time the consumer consumes, it puts a new message in the queue to the producer.

So in this way, a 'token' provides feedback from the consumer to producer that throttles the producer to the speed of consumer.

A finesse if appropriate is for the messages to simply be returned, rather than fresh allocations each time. If its single-process, and message data is large and fixed size, this can itself be a powerful driver for the adoption of this design.

好倦 2024-08-28 00:06:08

I had to use the COM library for MSMQ. I found the following link which helped.

http://blog.codebeside.org/archive/2008/08/27/counting-the-number-of-messages-in-a-message-queue-in.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文