I recently worked in a larger project where I touched the topic of distributed systems in the c# world the first time.
I found that wcf is fantastic for remote procedure calls, but how do you add event communication between services using only wcf?
Here the project requirements:
- We had ~15 different services for different aspects of the whole system
- each service ran in its own process
- WPF clients could use RPC on the services and could subscribe to service events
- the services needed to do RPC on each other and also subscribed to events of other services
- services were hosted on the same machine and on different machines within local ethernet
- communication was via TCP
- They were all long running services (planned uptime ~2 years)
- The system manages long running company workflows
- eventing was realized via a publisher and subscriber
- events must not be lost
- during busy hours many events have to be managed between all services
Now the evil part: for event communication, a central publish-subscribe service was used. For every subscriber it had (multiple) callback channels and kept them open forever (via a keep-alive-ping). Well I read: keeping WCF channels open forever is kind of a WCF-antipattern. We also had many problems with that solution.
Is there a better alternative than one of these?
Use a message queueing system (like MSMQ, RabbitMQ, ZeroMQ...)
- You can not only use WCF
- you have to deploy an addtitional Queueing system (while ZeroMQ would only be a dll!)
- more wrapping code will be needed to handle the queues
- as far as I saw you normally need to poll the queues
Use simple or long polling
- this will produce quite some network traffic
Use Observer Pattern (implement RegisterListener/HandleEvent RPCs with WCF)
- Events can only be consumed by WCF services, not by WPF clients
- Additional wrapping code is needed