zero_coding zero_coding - 20 days ago 5
C# Question

Communication between microservices pipeline

I want to use microservices architecture for my next project based on ASP.NET core.

I could exchange between the services via REST but it is really heavy to maintain.

Is there an other way for communication between microservices, for example over event bus like vertx.

I could use rabbitmq, but do not know, if it is a good option.

Answer

I think Rabbit MQ is going to work OK, especially if you have many consumers i.e. need load balancing, and/or if you need messages to be persistent, and also if conceptually, your micro-services are OK processing messages.

Otherwise, since you’re considering REST, I’d recommend WCF instead.

Just ignore Microsoft’s examples, those are too complex. You need to make an assembly containing protocols (in WCF terminology, service contracts) + messages they send/receive (in WCF terminology, data contracts) that’ll be shared between your services. Having a shared assembly will allow you to get rid of that enterprise-style XML configuration nonsense. This will also make maintenance simpler than REST, because the compiler is going to verify the correctness of your network calls: you forget to update one service after changing a protocol, and the service will stop compiling.

Here’s my demo which uses WCF to implement zero-configuration client-server communications in C#. It’s currently set up to use named pipe binding i.e. will only work locally. But it’s easy to switch from NetNamedPipeBinding to NetTcpBinding which will do networking just fine.

P.S. If you’ll pick WCF, don’t forget the abstraction can and will leak. Any network call may fail with any network-related exception. Also you’ll need to reconnect sometimes (if you don’t want to, and your don’t have too many messages per second, you can use a connection-less protocol like NetHttpBinding but those are much less performant).

Comments