问题
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.
The project is self-hosted.
Here is a quick unit test showing the blocking of the current request instead of deferring it to the background:
- https://gist.github.com/lmcnearney/5407097
回答1:
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.
A few pointers:
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.
Hope this helps...
来源:https://stackoverflow.com/questions/15897147/servicestack-how-to-make-inmemorytransientmessageservice-run-in-a-background