WCF - 可以纯粹通过配置在单线程和多线程之间切换吗?

发布于 2024-11-19 02:13:43 字数 407 浏览 4 评论 0原文

我开发了一个 WCF 服务(它恰好监听 MSMQ 队列)。我没有放入任何特定的线程相关代码,因此它默认以多线程方式运行。对于实时环境来说,这很好(而且很可能是理想的),但目前该服务仍在测试中。我无法完全控制消息何时出现在测试队列上,因此我处于可能同时出现许多消息的情况。

该服务执行大量诊断日志记录,但我必须使用的日志记录机制(“公司标准”)不是线程感知的。所以结果是,几个线程同时运行,我的日志记录变得一团糟。我想做的就是在测试时将线程数限制回 1。

我已经看到了在代码中实现单线程的各种方法,但我真的不喜欢将一个二进制文件发布到 Test 并将另一个二进制文件发布到 Live。

我知道 WCF 非常热衷于使用配置文件,所以我想知道是否有某种纯粹基于配置的方法来告诉 WCF 服务是否以单线程或多线程模式进行侦听?

TIA, 皮特

I have developed a WCF service (which happens to listen on an MSMQ queue). I haven't put any specific threading-related code in, so it runs by default in a multi-threaded manner. This will be fine (and most probably desirable) for a live environment, however right now this service is still being tested. I don't have total control over when messages appear on the test queue, so I'm in a situation where many could appear at once.

The service does a lot of diagnostic logging, but the logging mechanism I am obliged to use (the "company standard") is not thread-aware. So the upshot is that then several threads run at once my logging becomes a total mess. What I would like to do is to throttle the number of threads back to 1 while I am testing.

I have seen various ways of achieving single-threadedness in code, but I really don't fancy releasing one binary to Test and a different binary to Live.

I know that WCF is pretty hot on the use of config files so I was wondering whether there was some way, based purely in config, of telling a WCF service whether to listen in a single-threaded or multi-threaded mode?

TIA,
Pete

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

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

发布评论

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

评论(2

瀟灑尐姊 2024-11-26 02:13:43

请参阅此问题:WCF MSMQ 使用者线程计数

很高兴这有帮助!

See this question: WCF MSMQ consumer thread count

Glad this helped!

清泪尽 2024-11-26 02:13:43

您可以将所有代码放置在服务中的包装类中,依赖注入框架可以在运行时注入该包装类。

通过依赖注入,您可以配置是将依赖项实现为单例还是每个请求实例。

但是,在“单线程模式”下测试应用程序是不够的。

或者,为什么不在日志记录信息中包含当前执行的线程 ID - 然后根据需要按线程 ID 过滤日志文件?

You could place all of the code within the service, inside a wrapper class that a Dependency Injection framework could inject at runtime.

With Dependency Injection you can configure whether to implement the dependency as a singleton, or as a per request instance.

However, testing the app in "single threaded mode" will not be sufficient.

Alternatively, why not include the current executing threadid in the logging info - then filter the logfile by threadid as required?

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