0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Macでgrpc_cliを手早く動かす

Last updated at Posted at 2019-11-16

TL;DR;

あれこれインストール・ビルドを省いて、dockerイメージつかう

docker run --network=host --rm znly/grpc_cli ls localhost:1111 -l

homebrewでは単体でインストールできない

grpc同梱なので、依存libraryのインストール、ビルドを気長にやる必要がある

  • 自分の場合は25分コースだった
~ ❯❯❯ brew tap grpc/grpc
~/w/a/schema ❯❯❯ brew info grpc                                                                                                                                                                                        ✘ 130 wip ✭ ✱ ◼
grpc: stable 1.25.0, HEAD
Next generation open source RPC library and framework
https://grpc.io/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/grpc.rb
==> Dependencies
Build: autoconf ✔, automake ✔, libtool ✔
Required: c-ares ✘, gflags ✘, openssl@1.1 ✘, protobuf ✘
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 4,149 (30 days), 12,430 (90 days), 33,431 (365 days)
install_on_request: 2,945 (30 days), 9,072 (90 days), 28,668 (365 days)
build_error: 0 (30 days)

初回実行時だけdockerイメージのダウンロード発生

サイズは9MBくらい

使用例

# server reflection有効にしたgRPCサーバーへの接続
docker run --network=host --rm znly/grpc_cli:latest ls localhost:50051
grpc.reflection.v1alpha.ServerReflection
helloworld.Greeter

# server reflection未対応のgRPCサーバーへ接続をトライして失敗
~ ❯❯❯ docker --network=host run --rm znly/grpc_cli:latest ls localhost:2222
Received an error when querying services endpoint.

evansとgrpc_cli

evansはhomebrewでインストールできるしシングルバイナリーとして配布されてるのでインストールが楽で、rpcメソッドコールとかやりやすいUI

他方、その場でさっとprotobufの内容を取得できるのは、grpc_cliにしか無い気がする。

~ ❯❯❯ docker run --network=host --rm znly/grpc_cli:latest ls localhost:2222 -l
ls localhost:50051 -l
filename: helloworld.proto
package: helloworld;
service Greeter {
  rpc SayHello(helloworld.HelloRequest) returns (helloworld.HelloReply) {}
  rpc SayHelloAgain(helloworld.HelloRequest) returns (helloworld.HelloReply) {}
}
# skip ...

試行錯誤

  • --network=host 重要だった
    • cliがホスト側のネットワークに繋ぐときに必要
  • うまく接続できないときとかは使うdockerイメージをnamely/grpc-cli に切り替えるとエラー表示が詳しくなる
    • ただし250MBくらいのイメージをダウンロードしないといけない
# znly/grpc_cli 利用時のエラーログ
➜  ~ docker run  --rm znly/grpc_cli ls 0.0.0.0:1111 -l
Received an error when querying services endpoint.
# namely/grpc-cli利用時のエラーログ
➜  ~ docker run --rm namely/grpc-cli ls localhost:1111
Received an error when querying services endpoint.
ServerReflectionInfo rpc failed. Error code: 14, message: failed to connect to all addresses, debug info: {"created":"@1573922174.884215300","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3934,"referenced_errors":[{"created":"@1573922174.884187900","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":393,"grpc_status":14}]}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?