Skip to content

Commit

Permalink
example(issue-35): register reflection service so grpc example works …
Browse files Browse the repository at this point in the history
…with insomnia etc.
  • Loading branch information
Zaba505 committed Dec 17, 2023
1 parent b99d7ee commit 3891b17
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions example/simple_grpc/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
# https://opensource.org/licenses/MIT

FROM scratch
EXPOSE 9080
COPY simple_grpc /
ENTRYPOINT ["/simple_grpc"]
9 changes: 8 additions & 1 deletion example/simple_grpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import (

"go.opentelemetry.io/otel"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)

type simpleService struct {
simple_grpc_pb.UnimplementedSimpleServer
}

func (*simpleService) Echo(ctx context.Context, req *simple_grpc_pb.EchoRequest) (*simple_grpc_pb.EchoResponse, error) {
_, span := otel.Tracer("main").Start(ctx, "simpleServer.Echo")
_, span := otel.Tracer("main").Start(ctx, "simpleService.Echo")
defer span.End()
resp := &simple_grpc_pb.EchoResponse{
Message: req.Message,
Expand All @@ -48,6 +49,12 @@ func initRuntime(bc bedrock.BuildContext) (bedrock.Runtime, error) {
brgrpc.ServiceName("simple"),
brgrpc.Readiness(&health.Readiness{}),
),
// register reflection service so you can test this example
// via Insomnia, Postman and any other API testing tool that
// understands gRPC reflection.
brgrpc.Service(func(s *grpc.Server) {
reflection.Register(s)
}),
)
return rt, nil
}
Expand Down
5 changes: 5 additions & 0 deletions example/simple_grpc/simple_grpc.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2023 Z5Labs and Contributors
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT

syntax = "proto3";

package simple_grpc_pb;
Expand Down
1 change: 1 addition & 0 deletions example/simple_http/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
# https://opensource.org/licenses/MIT

FROM scratch
EXPOSE 8080
COPY simple_http /
ENTRYPOINT ["/simple_http"]

0 comments on commit 3891b17

Please sign in to comment.