MSMQ - 快速生产者/慢速消费者
我在消息传递(使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有使用过 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.
我必须使用 MSMQ 的 COM 库。我发现以下链接有帮助。
http://blog.codebeside.org/archive/2008/08/27/counting-the-number-of-messages-in-a-message-queue-in.aspx
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