サーバーリフレクションと動的クライアント
gRPCサーバーリフレクションを有効にし、事前にコンパイルしたスタブなしで、ツールやクライアントが実行時にサービスとメッセージスキーマを検出できるようにします。
「サーバーリフレクションと動的クライアント」はCoddyKit上の無料gRPC & High Performance APIsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはgRPC & High Performance APIs学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 gRPC & High Performance APIsコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
The Stub Discovery Problem
Normally a client needs the .proto files compiled into stubs to call a service. That is inconvenient for debugging tools and generic clients.
Server reflection lets a server describe its own API at runtime.
What Reflection Exposes
The reflection service answers questions like:
- Which services does this server host?
- What methods does a service have?
- What are the request/response message schemas?
It returns the underlying FileDescriptorProto data.
Enabling Reflection in Go
Register the reflection service on your gRPC server with a single call.
import 'google.golang.org/grpc/reflection'
s := grpc.NewServer()
pb.RegisterServiceServer(s, &svc{})
reflection.Register(s)Enabling Reflection in Java
In Java add the ProtoReflectionService when building the server.
Server server = ServerBuilder.forPort(9090)
.addService(new MyServiceImpl())
.addService(ProtoReflectionService.newInstance())
.build();Listing Services with grpcurl
With reflection on, grpcurl can list services without a proto file.
grpcurl -plaintext localhost:9090 listDescribing a Method
You can inspect a method's input and output schema directly from the server.
grpcurl -plaintext localhost:9090 describe my.pkg.Service.GetUserCalling Without Stubs
Reflection lets you invoke methods by sending JSON; the tool maps it to protobuf using the discovered schema.
grpcurl -plaintext -d '{"id": 7}' localhost:9090 my.pkg.Service.GetUserDynamic Clients in Code
Libraries can build messages dynamically from descriptors fetched via reflection, enabling generic gateways and admin tools that work against any gRPC server.
The Reflection Protocol
Reflection is itself a gRPC service: grpc.reflection.v1.ServerReflection. It uses a bidirectional stream where clients ask and the server streams back descriptors.
Security Considerations
Reflection reveals your entire API surface. In production:
- Disable it on public-facing edges, or
- Restrict it to internal networks / authenticated callers
It is invaluable in dev and staging.
When to Use It
Reflection shines for debugging, building generic UIs (like BloomRPC/Postman), and admin tooling. For high-throughput app clients, precompiled stubs are still faster and safer.
Quick Check
Test your reflection knowledge.
Recap
You learned server reflection and dynamic clients:
- Reflection lets a server describe its own API at runtime
- Enable it with
reflection.Register(Go) orProtoReflectionService(Java) - Tools like
grpcurlcan list, describe, and call without stubs - Dynamic clients build messages from fetched descriptors
- Restrict reflection in production for security
よくある質問
「サーバーリフレクションと動的クライアント」レッスンは無料ですか?
はい。「サーバーリフレクションと動的クライアント」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、gRPC & High Performance APIsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 gRPC & High Performance APIsコースには全4レッスンが含まれています。
「サーバーリフレクションと動的クライアント」で何を学びますか?
gRPCサーバーリフレクションを有効にし、事前にコンパイルしたスタブなしで、ツールやクライアントが実行時にサービスとメッセージスキーマを検出できるようにします。 ブラウザで直接実行するハンズオンコードでgRPC & High Performance APIsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
gRPC & High Performance APIsを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのgRPC & High Performance APIsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「サーバーリフレクションと動的クライアント」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このgRPC & High Performance APIsレッスンでコードを書いて実行できますか?
はい。すべてのgRPC & High Performance APIsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- gRPC-Webの統合
- gRPCurlとBloomRPC
- サービスディスカバリのパターン
- サーバーリフレクションと動的クライアント