ServiceStack: How to make InMemoryTransientMessageService run in a background

随声附和 提交于 2019-12-10 07:09:09

问题


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 implement WaitForNotifyOnAny() 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 its Publish() 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!