4

I work in a fin tech company that develops trading systems using Meta Trader Manager Api implemented in C#, we have our own process that hides the meta trader dependencies and exposes server to client and client to server operations to other systems we have via tcp client and Socket class.

We were thinking on switching to grpc but the main concern i have is that i don't see an easy implementation of server to client notifications in grpc.

The only solution i saw was a work around on grpc long lived client to server stream where you need to keep the call alive in the server using a lock or an endless loop and save the client's write stream in the server side and calling it when the notification event is triggered.

plus on the client side i see that i need to create for each notification's event handler an endless loop as well to call ResponseStream.MoveNext() for subsequent notifications.

it seems to me that either grpc is not built for this usage or I'm missing something.

  • 2
    gRPC is *absolutely* designed for that scenario; either a server-streaming or full-duplex call would be fine - then you need an async write at the server *when the data becomes available*. One way to do that is to create a Channel-T or an observable (RX), and use that as the bridge – Marc Gravell Apr 25 '22 at 23:17
  • I've been testing different techniques for this (SignalR, raw web sockets, custom polling) just recently and returned to use gRPC very similar to how Marc Gravell mentioned it, as it also fulfilled my need for RPC and a capable C++ "client" in one battle tested solution. Only thing ugly about it is it not being available directly in browsers, needing gRPC-web. – Ray Apr 26 '22 at 02:07
  • Thanks guys for the quick response, i understand from you answers that this is the way to go in grpc, server needs to keep the stream alive by blocking the method call, that way the client will be blocked when calling ResponseStream.MoveNext(). it seems like there is a serious overhead implementing server to client notification( code wise) compared to other solutions. maybe the performance part of grpc will worth the while. Thanks again for the answers. – Amit Langer Apr 26 '22 at 07:19

0 Answers0