Introduction to Remote Procedure calls. It contains basic to advance level Microservices API's.
syntax = "proto3";
message Request {
int64 phone_number =1;
}
message Response {
int64 phone_number = 1;
string message = 2;
int32 status_code =3;
}
service CreateService{
rpc Service (Request) returns (Response);
}
Unary API basic API user Get request and Server Send Response
Unary API
Server Streaming API server continous send data to user in simple User request in one time and server send multiple response
Server Streaming API
Client Streaming API is opposite to server streaming
Client Streaming API
Bi-Directional API its like a chat Client and Server send data at same time
BI-Directional API
Create Update Read data form Monogo db using gRPC
Crud API Mongodb
Create Update Read data form Postgres using gRPC
Crud API Postgres
Deadline if the response form server not coming in a particular time how to call deadline
Deadline
Error Handling in gRPC its just a basic how to do for More :
Error handling
Server in go and Client in java. Multiple Language combat using Protos same proto use server(Go) and client (Java)
Lang Combat
Reflection Its a great a tool See our gRPC code test our code. Best to use
Reflection
ssl security in gRPC
ssl security
The answer is gRPC encode and decode the data when send and recive it take less time if we send data in the form of small packet
syntax = "proto3";
package uploadpb;
message UploadChunkRequest{
bytes file_chunk = 1;
}
message UploadResponse{
string message = 1;
int32 code = 2;
}
service UploadService{
rpc UploadFileService (stream UploadChunkRequest) returns (UploadResponse){};
}
C_SIZE = 64*64
req := &uploadpb.UploadChunkRequest{}
for start := 0; start < len(image); start += C_SIZE {
if start+C_SIZE > len(image) {
req.FileChunk = image[start:len(image)]
} else {
req.FileChunk = image[start : start+C_SIZE]
}
if err := stream.Send(req); err != nil {
log.Fatalln("Error in send:", err)
}
Slack bot user read and send message (Basic) using gRPC. DB used postgres and Mongodb. It will dump the data in db of user message and bot response.
syntax = "proto3";
message CommonResponse {
int32 code = 1;
string message = 2;
}
message SlackDumpRequest {
string question_from_user = 1;
string answer_from_ai =2;
bool mongodb_enable = 3;
bool postgres_enable = 4;
}
message SlackDumpResponse {
CommonResponse CommonResponse = 1;
}
service SlackBotService {
rpc SlackDumpingGround(SlackDumpRequest) returns (SlackDumpResponse);
}
The answer is very simple it's a DS Linkedlist type not linkedlist its just same as linkedlist it just always store the previous hash/id.
- IBM
- Bitcoin
- Samsung
- etc Many more
type Block struct {
Data string
PrevBlockHash string
Hash string
}
Google Authentication Sample and Expose the Micoservice API to others
go get golang.org/x/oauth2
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
service OAuthService {
rpc GetOAuthService (OAuthRequest) returns (OAuthResponse);
rpc GetCodeState(OAuthCodeRequest) returns (OAuthCodeResponse) {
option (google.api.http) = {
post: "/v1/oauth/{code}/{state}"
body: "*"
};
}
}
}
protoc -I/usr/local/include -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=google/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api,plugins=grpc:. oauth2/proto/oauth.proto
protoc -I /usr/local/include -I. -I $GOPATH/src -I $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:. oauth2/proto/oauth.proto
- There are 3 servers in this OAuth.
- Go through the generate.sh file First
- Ist is for gRPC server. (Brain)
- 2nd is the API Expose server (Rest)
- 3rd is for the web page render/ UI run for an example For oAuth (gWeb)
curl -X POST "http://localhost:5051/v1/oauth/10001/true"
syntax = "proto3";
package uploadpb;
message UploadChunkRequest{
bytes file_chunk = 1;
}
message UploadResponse{
string message = 1;
int32 code = 2;
}
service UploadService{
rpc UploadFileService (stream UploadChunkRequest) returns (UploadResponse){};
}
Image send in the form of small packets coz large image takes long time to send in client and server side
It takes time coz gRPC encrept and decrept the data when send and recieve if we send small packages it will take less amount of time
https://jbrandhorst.com/post/grpc-binary-blob-stream/
// #server-run
go run face-detection/server/app-server.go
or
make server
// #client-run
go run face-detection/client/app-client.go
or
make client
rec, err := face.NewRecognizer(dataDir)
if err != nil {
log.Println("Cannot initialize recognizer", err)
return err
}
defer rec.Close()
dataImage := filepath.Join(dataDir, "sumit.jpg")
faces, err := rec.RecognizeFile(dataImage)
if err != nil {
log.Println("Can't recognize: %v", err)
return err
}
// Pass samples to the recognizer.
rec.SetSamples(samples, totalF)
sumit, err := rec.RecognizeSingle(image)
if err != nil {
log.Println("Can't recognize: %v", err)
return err
}
if sumit == nil {
log.Panicln("Not a single face on the image")
return err
}
fmt.Println("Face Recorganize")
// #server-run
go run face-detection/server/app-server.go
or
make server
// #client-run
go run face-detection/client/app-client.go
or
make client
Email: [email protected]