Slide 17
Slide 17 text
4.サンプルのポイント解説(client)
Future main(List args) async {
// 1. gRPC接続チャンネルを作る
final channel = ClientChannel(
'localhost',
port: 50051,
options: ChannelOptions(
credentials: ChannelCredentials.insecure(),
codecRegistry:
CodecRegistry(codecs: const [GzipCodec(), IdentityCodec()]),
),
);
// 2. protoファイルから生成したClientのオブジェクトを作る
final stub = TodoServiceClient(channel);
// 3. gRPCのAPIを呼ぶ。
try {
final response = await stub.createTodo(
CreateTodoRequest(
todo: Todo(title: 'title3', description: 'description3')),
options: CallOptions(compression: const GzipCodec()),
);
} catch (e) { ... }
await channel.shutdown();
}