Interprocess pubsub without network dependency

痴心易碎 提交于 2019-12-12 08:17:05

问题


Suppose I have no network card installed on my computer, and I would like to have functionality similar to the following:

Process 1 will publish messages to some URI, say "Uri1"

var publisher = new Publisher("Uri1");
publisher.publish(new Message("Somedata");

Process 2 will both listen for messages on "Uri1" and publish messages to "Uri2"

var subscriber = new Subscriber("Uri1")
subscriber.MessageReceived += data => Console.Writeline(data.ToString());
var publisher = new Publisher("Uri2")
publisher.Publish(new Message("SomeMoreData"))

Process 3 will listen for messages from both URIs

var subscriber = new Subscriber("Uri1")
subscriber.MessageReceived += data => Console.Writeline(data.ToString());
var anotherSubscriber = new Subscriber("Uri2")
anotherSubscriber.MessageReceived += data => Console.Writeline(data.ToString());

All processes run on the same computer. After some research I believe MSMQ is the way to go (using queue names as URIs) but the implementation question remains. I came across several possibilities:

Using MSMQ directly
The problem I have with this approach is that I would have to manage the queues my self e.g. creation, population, purging... also from what I read I may encounter many pitfalls and limitations of MSMQ seeing as I am not experienced with it

Using NServiceBus, MassTransit or RhinoServiceBus (all use MSMQ) They all seem competent, especially NServiceBus, but I can't seem to figure out from the documentation how to extract the basic pubsub functionality from any of them so that I could encapsulate it in an interface similar to the above

Using WCF(over MSMQ) Again this looks like a good option, but seeing as I am far from a WCF expert I would like to make sure this is the way to go before I start delving into it

Our approach up until now has relied on PGM multicast which worked well enough, but the new requirement of working without a network card forces us to use another mechanism for offline work, at least as far as I know

Thanks!


回答1:


In the end, we chose a shared memory ready-made solution: http://pubsub.codeplex.com/ Initial testing imply it works well for our case




回答2:


Well, according to http://answers.yahoo.com/question/index?qid=20080616091430AAAxTJB you can use the loopback address without a NIC installed. Maybe you can use that functionality to continue using your existing code?

Note: I have not tested this, it was just an idea.



来源:https://stackoverflow.com/questions/2232047/interprocess-pubsub-without-network-dependency

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