gRPC + Managing Graph Example
Prerequisites
Implemented Graph is undirected without weights.
Implemented Graph represents an adjacency list.
Installing
npm install
Using
- Transform protobuff to JS and TS definition files
npm run proto: generate
- Run server
npm run server
- Run client
npm run client <action> <param1>
Actions:
- add:node - Adds node to the graph
Example: npm run add:node A
-
remove:node - Remove node from thee graph (note: not implemented yet)
-
add:edge - Adds edge to the graph
Example: npm run add:node A_B
- remove:edge - Remove edge from thee graph
Example: npm run remove:node A_B
Working scenario
- Start server
$ npm run server
Presetted Nodes:
A ->
B ->
C ->
gRPC Server listening on 50051
- In different terminals start several clients
# terminal 1
$ npm run client add:node B
Server Response:
A ->
B ->
C ->
H ->
# terminal 2
$ npm run client add:edge A:B
Server Response:
A -> B,
B -> A,
C ->
H ->
#terminal (arrived broadcast message)
Broadcasting: Updated Graph:
A -> B,
B -> A,
C ->
H ->
Testing
npm test
or in watch mode
npm run test:watch
Roadmap
- Every client should provide prompt to actions and params (cli)
- Remove disconnected clients from stored clients list
- Get rid of callbacks in GraphDispatcherHandler (client: grpc-promise package)