This project is a basic distributed system used to record the data of baseball game. Using gRPC (Golang), replica-set (mongoDB), Cobra (CLI) this project could ...
- Trigger the function with gRPC.
- Create or update the the baseball game record with CLI terminal.
- Backup database automatically.
- [筆記] 實作分散式計分系統(一) : 基礎架構
- [筆記] 實作分散式計分系統(二) : Replica Set in Container
- [筆記] 實作分散式計分系統(三) : gRPC and Protobuf
- [筆記] 實作分散式計分系統(四) : Build up an interactive CLI with Cobra
- Each node is a container.
- Replica set are composed of three mongoDB node - Rs1(Primary), Rs2(Seconary) and Rs3(Seconary).
- Server node is a gRPC server, the exposed port is 50051.
- Client node could call RPC function through CLI.
$ cd $GOPATH/src
# Git clone from github
$ git clone https://github.com/amosricky/Simple_Distributed_System.git
# Change path to project
$ cd ./Simple_Distributed_System
# Run it
$ docker-compose -f server_node.yml up
# Change path to project
$ cd ./Simple_Distributed_System
# Run it
$ docker-compose -f client_node.yml run client_node
$ game help
Get & Modify game record
Usage:
game [command]
Available Commands:
add Add point by game ID.
list Get game list. (Contain gameName & gameID)
new Create a new game.
score Get score by game ID.
Flags:
-h, --help help for game
$ game new -h
Create a new game.
Usage:
game new [flags]
Flags:
-h, --help help for new
-n, --name string game name
$ game list -h
Get game list. (Contain gameName & gameID)
Usage:
game list [flags]
Flags:
-d, --dbIP string database ip (default "127.0.0.1")
-p, --dbPort int32 database port (default 27041)
-h, --help help for list
$ game add -h
Add point by game ID.
Usage:
game add [flags]
Flags:
-a, --add int32 add point
-h, --help help for add
-i, --id string game id
-r, --round int32 round ([min]1 [max]9)
-t, --team int32 team ([0]home [1]visitor) (default -1)
$ game score -h
Get score by game ID.
Usage:
game score [flags]
Flags:
-d, --dbIP string database ip (default "127.0.0.1")
-p, --dbPort int32 database port (default 27041)
-h, --help help for score
-i, --id string game id
- Create a new game called "testGame", and then check game list.
- Add 5 point for home team on second round.
- Add 3 point for guest team on second round.
- Read the data from different replica node.
(Because we use replica set as database node which could backup the data automatically, we could READ the data from every replica set node.)
- Use replica set(mongoDB) to backup data automatically.
- Use protobuf to define the baseball game structure.
- Use gRPC instead of Restful API which work on http2.
- Use Cobra to define a basic CLI on client node.
.
├── client // Define the client node.
│ ├── clientNode.go // Create an loop to read stdin stream.
│ └── cmd // Use Cobra to define the CLI command.
│ └── cmd.go
├── client_node // Dockerfile - client node.
├── client_node.yml // docker-compose.yml - client node.
├── conf
│ └── app.ini // System configuration
├── go.mod
├── go.sum
├── LICENSE
├── pb
│ ├── game.pb.go // The gRPC struct created from game.proto
│ └── game.proto // Define the protobuf struct.
├── README.md
├── replica // Replica set configuration
│ ├── config
│ │ └── mongod.yml
│ └── data // The mongoDB data
│ ├── rs1
│ ├── rs2
│ └── rs3
├── replica_set.js // MongoDB command used to create replica set.
├── server // Define the server node.
│ └── serverNode.go // Create gRPC server.
├── server_node // Dockerfile - server node.
├── server_node.sh // Use to run server node after mongoDB started.
├── server_node.yml // docker-compose.yml - server node.
└── setting // Initialize the configuration
└── setting.go
...
- Golang >= 1.13.7
- docker-compose
- mongo >= 4.2





