-
Notifications
You must be signed in to change notification settings - Fork 25
第9回Go勉強会の課題@luccafort #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Streamなレスポンスを受け取ったときにどうRubyで扱うのかわからなかったのでチュートリアルで実装を参考にした https://github.com/grpc/grpc.io/blob/master/content/docs/tutorials/basic/ruby.md
http_response = http_client.say_hello(request_opts) | ||
puts http_response | ||
|
||
puts '=====================' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ファイルを分割しても良かったんですが元々Go側のコードも分割はしてなかったので1つのファイルで実行しています。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この標準出力は通常のレスポンスとStreamなレスポンスをわかりやすくする境界線として出力しているだけで特に意味はないです。
|
||
request_opts = Sample::HelloRequest.new(first_name: '太郎', last_name: '兼進') | ||
stream_request = stream_client.pereodic_hello(request_opts) | ||
stream_request.each { |req| puts req } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
今回、検証はしてないけどこの block
内で実行されているコード内で処理を抜けたい場合は条件式などで抜け出す条件を記載して return
することになるのかな? 🤔
block
内で break
すると意図しない挙動になるってチェリー本に書いてたのは記憶してるが詳細は忘れた。
# Generated by the protocol buffer compiler. DO NOT EDIT! | ||
# Source: proto/helloworld.proto for package 'sample' | ||
|
||
require 'grpc' | ||
require 'proto/helloworld_pb' | ||
require './proto/helloworld_pb' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは気づかない…。
# Generated by the protocol buffer compiler. DO NOT EDIT! | ||
# Source: proto/notification.proto for package 'sample' | ||
|
||
require 'grpc' | ||
require 'proto/notification_pb' | ||
require './proto/notification_pb' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは気づかない…。
課題
https://mf.esa.io/posts/131091#%E8%AA%B2%E9%A1%8C
ハマりどころ
make setup
でgem install grpc-tools
がSystemのほうのGemを参照していた少し困った。解決策は書いたが環境系の問題に引っかかると面倒。
https://moneyforward.slack.com/archives/CVB3XK04U/p1587301291079800
対応としてあっているのかわからないが自動生成されたコードの
require 'proto/xxxx'
というファイルのパスが正しくないためにclient.rb
がLoad Error
になり続けて原因究明するのに時間がかかった。最終的に
require
していないgrpc
関係ないコードを書く → OKrequire
を復活させてgrpc
関係ないコードを書く → NGrequire
させてgrpc
関係ないコードを書く → OKだったので
require
が正常に機能していないことを確認してパスを書き換えたらうまくいった……が自動生成されたものの読み込みに問題があるのを疑うのはなかなか厳しい。