Below you will find pages that utilize the taxonomy term “Tonic”
Posts
read more
rust-analyzer and tonic
Solution: https://github.com/rust-analyzer/rust-analyzer/issues/5799
References: https://jen20.dev/post/completion-of-generated-code-in-intellij-rust/
build.rs:
fn main() -> Result<(), Box<dyn std::error::Error>> {
// gRPC Healthcheck
tonic_build::compile_protos("proto/grpc_health_v1.proto")?;
Ok(())
}
But, because this compiles the proto(s) at build time, the imports aren’t available to Visual Studio Code and rust-analyzer
pub mod grpc_health_v1 {
tonic::include_proto!("grpc.health.v1");
}
// These imports would be unavailable and error
use grpc_health_v1::{
health_check_response::ServingStatus,
health_server::{Health, HealthServer},
HealthCheckRequest, HealthCheckResponse,
};
However,
"rust-analyzer.cargo.loadOutDirsFromCheck": true,
Posts
read more
Using tonic
Microsoft’s akri uses tonic to provide gRPC.
For the gRPC Health-checking Protocol proto:
./proto/grpc_health_v1.proto:
syntax = "proto3";
package grpc.health.v1;
service Health {
rpc Check(HealthCheckRequest) returns (HealthCheckResponse);
rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse);
}
message HealthCheckRequest {
string service = 1;
}
message HealthCheckResponse {
enum ServingStatus {
UNKNOWN = 0;
SERVING = 1;
NOT_SERVING = 2;
SERVICE_UNKNOWN = 3; // Used only by the Watch method.
}
ServingStatus status = 1;
}
Tonic supports compiling protos using build.rs:
fn main() -> Result<(), Box<dyn std::error::Error>> {
// compile refers to the path
tonic_build::compile_protos("proto/grpc_health_v1.proto")?;
Ok(())
}
And then useing these:
Posts
read more
gRPC Healthchecking in Rust
Golang
Go provides an implementation gprc_health_v1 of the gRPC Health-checking Protocol proto.
This is easily implemented:
package main
import (
pb "github.com/DazWilkin/.../protos"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
)
func main() {
...
serverOpts := []grpc.ServerOption{}
grpcServer := grpc.NewServer(serverOpts...)
// Register the pb service
pb.RegisterSomeServer(grpcServer, NewServer())
// Register the healthpb service
healthpb.RegisterHealthServer(grpcServer, health.NewServer())
listen, err := net.Listen("tcp", *grpcEndpoint)
if err != nil {
log.Fatal(err)
}
log.Printf("[main] Starting gRPC Listener [%s]\n", *grpcEndpoint)
log.Fatal(grpcServer.Serve(listen))
}
Because it’s gRPC, you need an implementation of the proto for the client, one is provided too grpc-health-probe: