问题描述
需要做什么才能让 InMemoryTransientMessageService 在后台线程中运行?我使用
What needs to be done to make InMemoryTransientMessageService run in a background thread? I publish things inside a service using
base.MessageProducer.Publish(new RequestDto());
它们会在服务请求中立即执行.
and they are exececuted immediately inside the service-request.
该项目是自托管的.
这是一个快速的单元测试,显示了当前请求的阻塞而不是将其推迟到后台:
Here is a quick unit test showing the blocking of the current request instead of deferring it to the background:
推荐答案
没有什么开箱即用的.你将不得不建立自己的.看看 ServiceStack.Redis.Messaging.RedisMqHost
- 你需要的大部分东西都在那里,而且与 ServiceStack 相比,它可能更简单(一个线程完成所有事情)让你开始.Redis.Messaging.RedisMqServer
(队列监听一个线程,每个工作线程一个).我建议您参加该课程并根据您的需要进行调整.
There is nothing out of the box. You would have to build your own. Take a look at ServiceStack.Redis.Messaging.RedisMqHost
- most of what you need is there, and it is probably simpler (one thread does everything) to get you going when compared to ServiceStack.Redis.Messaging.RedisMqServer
(one thread for queue listening, one for each worker). I suggest you take that class and adapt it to your needs.
一些提示:
ServiceStack.Message.InMemoryMessageQueueClient
未实现WaitForNotifyOnAny()
,因此您需要另一种方法让后台线程等待传入消息.- 密切相关的是,ServiceStack.Redis 实现使用主题订阅,在这个类中用于传输
WorkerStatus.StopCommand
,这意味着您必须找到一种替代方法来获取后台线程停止. - 最后,您可能需要调整
ServiceStack.Redis.Messaging.RedisMessageProducer
作为其Publish()
方法将请求的消息推送到队列并推送通道/队列TopicIn 队列的名称.阅读代码后,您可以看到这三个点是如何联系在一起的.
ServiceStack.Message.InMemoryMessageQueueClient
does not implementWaitForNotifyOnAny()
so you will need an alternative way of getting the background thread to wait to incoming messages.- Closely related, the ServiceStack.Redis implementation uses topic subscriptions, which in this class is used to transfer the
WorkerStatus.StopCommand
, which means you have to find an alternative way of getting the background thread to stop. - Finally, you may want to adapt
ServiceStack.Redis.Messaging.RedisMessageProducer
as itsPublish()
method pushes the message requested to the queue and pushes the channel / queue name to the TopicIn queue. After reading the code you can see how the three points tie together.
希望这有帮助...
这篇关于ServiceStack:如何让 InMemoryTransientMessageService 在后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!