概要
gRPCのInterceptorのClient側、Server側の基本的な使い方を紹介します。
環境
- golang 1.12.0
- grpc 1.18.0
Interceptorの種類
以下の4つがあります。今回はUnaryの方の使い方を説明します。
以前Bool Query と Dis Max Query の違いについて書きました。
今回はその中で出てきたMulti Match Query
のtypeの違いについて書きます。
どれも複数のフィールドに対して実行するクエリですが、それぞれ用途が異なります。
curl -s -H "Content-Type: application/json" \ -XPOST localhost:9200/my_index/my_type/_bulk -d ' {"index": {"_id": "1"}} {"title": "Quick brown rabbits", "body": "Brown rabbits are commonly seen."} {"index": {"_id": "2"}} {"title": "Keeping pets healthy", "body": "My quick brown fox eats rabbits on a regular basis."} {"index": {"_id": "3"}} {"first_name": "Will", "last_name": "Smith"} {"index": {"_id": "4"}} {"first_name": "Smith", "last_name": "Jones"} '続きを読む
gRPCで4MB以上のデータ転送をしようとすると
rpc error: code = ResourceExhausted desc = grpc: received message larger than max (xxxxxxx vs. 4194304)
のようなエラーが出ます。この上限はデフォルト値なのでgrpc.MaxRecvMsgSize()やgrpc.MaxCallSendMsgSize()を使うことで変更可能ですが、ドキュメントでも以下のように
Protocol Buffers are not designed to handle large messages. As a general rule of thumb, if you are dealing in messages larger than a megabyte each, it may be time to consider an alternate strategy.
ref: Techniques | Protocol Buffers | Google Developers
と、1メッセージがメガバイトを超えるのであれば別の手段で転送することを考えるべき、と言っています。
なので
のようにストリームで送るのが良さそうです。
続きを読むNginx + GoのApp
という構成をとっている時に、単純にデプロイでGoだけ更新するとNginxからは
[error] 1413#1413: *1 connect() failed (111: Connection refused) [error] 1412#1412: *3 connect() failed (111: Connection refused) [error] 1412#1412: *5 connect() failed (111: Connection refused)
このような111: Connection refused
エラーが起きて、クライアント側には502
エラーが返ってしまいます。
理由はデプロイ時にプロセスが一時的に落ちるためです。
これを防ぐためにCircusというソケットマネージャを利用します。