-1

Basically, I was exploring using gRPC for an event driven mechanism for exchanging info between a publisher and a number of subscribers within the same process (but different threads) of the application. The application is a C++ application.

Unfortunately, all the examples I see for gRPC pubsub use Google cloud which I do not need, since my requirement is in-process and localised. I saw a similar question for ZeroMQ (ZeroMQ, can we use inproc: transport along with pub/sub messaging pattern) and see that it is possible to do so in ZeroMQ.

Question:
Is in-process pub/sub feasible with gRPC without using Google cloud?
Are there any examples?
Or should I switch to ZeroMQ for my requirement?

user3666197
  • 1
  • 6
  • 50
  • 92
sn710
  • 581
  • 5
  • 20

1 Answers1

1

Q : "Or should I switch to ZeroMQ for my requirement?"

This last question seems, in the contrast to the prior two, decidable for me. Let's try it:

One may opt to use either a younger, lighweight or the fully-fledged, many more inter-operational protocols ready , though given just the inproc://-transport-class was mentioned, the latter may seem over-equipped for the task.

If just this transport-class is needed, one may instantiate data-pumps as purely I/O-thread-less Context()-instances, using an explicit request to do so :

#define Zero_IO_threads 0

void    *myCtx =                zmq_ctx_new ( Zero_IO_threads );
assert ( myCtx      && "FAILED: zmq_ctx_new ( ... )" );
                                zmq_ctx_set ( myCtx, ZMQ_BLOCKY, false );

void    *aPubSocket =           zmq_socket ( myCtx, ZMQ_PUB );
assert ( aPubSocket && "FAILED: zmq_socket ( ... )" );
...

void    *aSubSocket =           zmq_socket ( myCtx, ZMQ_SUB );
assert ( aSubSocket && "FAILED: zmq_socket ( ... )" );
         rc =                   zmq_setsockopt ( aSubSocket, ZMQ_SUBSCRIBE, "", 0 );
assert ( rc == 0    && "FAILED: zmq_setsockopt ( aSubSocket, ... )" );
...

         rc =                   zmq_bind ( aPubSocket, "inproc://#A" ); // Def inproc name "#A"
assert ( rc == 0    && "FAILED: zmq_bind ( aPubSocket, ... )" );

...
         rc =                   zmq_connect ( aSubSocket, "inproc://#A"); // Try connect to #A
assert ( rc == 0    && "FAILED: zmq_connect ( aSubSocket, ... )" );

// ___________________________________________aSubSocket can start receive messages
...

// ___________________________________________FINALLY: gracefully close & terminate
assert ( 0 == zmq_close ( aPubSocket ) && "FAILED: zmq_close( aPubSocket )" );
...
assert ( 0 == zmq_close ( aSubSocket ) && "FAILED: zmq_close( aSubSocket )" );    
...
assert ( 0 == zmq_ctx_term ( myCtx )   && "FAILED: zmq_ctx_term( myCtx )" );
user3666197
  • 1
  • 6
  • 50
  • 92