简体   繁体   English

MSMQ,从单个Windows服务读取多个队列消息

[英]MSMQ ,reading multiple Queue messages from a single windows Service

I need some design suggestions if any one could suggest one that would be great. 如果有人可以提出建议,我需要一些设计建议。

I implemented a WCF service that reads messages from a queue(MSMQ) on windows server and processes it further.Now I need to read the messages from another queue and process them seperately.I am confused to go with a new service or update the existing service which would do the both readings from different queues parallel. 我实现了一个WCF服务,该服务从Windows服务器上的队列(MSMQ)中读取消息并进一步处理它。现在我需要从另一个队列中读取消息并单独处理它们。服务将并行执行来自不同队列的两个读取。

I am thinking interms of performance which would be the best option to go ? 我在考虑绩效方面,哪一种是最佳选择?

You should be able to just have a separate thread for each consumer. 您应该能够为每个使用者使用一个单独的线程。 Below is the pseudo code. 下面是伪代码。 The only things you need to make sure is to signal stop to threads when service is being shut down. 您唯一需要确保的是在关闭服务时向线程发出停止信号。

new Thread(WorkerA) { IsBackground = true }.Start();
new Thread(WorkerB) { IsBackground = true }.Start();

void WorkerA() {
   while (true) { /* process queue a */ }
}

void WorkerB() {
   while (true) { /* process queue b */ }
}

Performance should be equivalent when talking about 1 service vs 2 services because it will still be a thread being scheduled by the operating system. 在谈论1个服务与2个服务时,性能应该是等效的,因为它仍然是操作系统正在调度的线程。 As for stability, you could be a little more resilient when splitting the services, but that still shouldn't be too much of an issue, I would expect that the single service approach should be stable enough within each thread. 至于稳定性,您在拆分服务时可能会更具弹性,但这仍然不是一个太大的问题,我希望单一服务方法在每个线程中都应该足够稳定。

In the end I would just go for the simplest approach. 最后,我只是选择最简单的方法。

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

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