diff --git a/grpc/ruby_client/client.rb b/grpc/ruby_client/client.rb new file mode 100644 index 0000000..9e1352d --- /dev/null +++ b/grpc/ruby_client/client.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'grpc' +require './proto/helloworld_services_pb' +require './proto/notification_services_pb' + +# 通常のレスポンス +http_client = Sample::Greeter::Stub.new( + '127.0.0.1:5502', + :this_channel_is_insecure +) + +request_opts = Sample::HelloRequest.new(first_name: 'John', last_name: 'Doe') +http_response = http_client.say_hello(request_opts) +puts http_response + +puts '=====================' + +# Streamなレスポンスを受け取ったとき +stream_client = Sample::Notifier::Stub.new( + '127.0.0.1:5502', + :this_channel_is_insecure +) + +request_opts = Sample::HelloRequest.new(first_name: '太郎', last_name: '兼進') +stream_request = stream_client.pereodic_hello(request_opts) +stream_request.each { |req| puts req } diff --git a/grpc/ruby_client/proto/helloworld_services_pb.rb b/grpc/ruby_client/proto/helloworld_services_pb.rb index 583dbf5..4cc973a 100644 --- a/grpc/ruby_client/proto/helloworld_services_pb.rb +++ b/grpc/ruby_client/proto/helloworld_services_pb.rb @@ -1,15 +1,16 @@ +# frozen_string_literal: true + # 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' module Sample module Greeter # The greeting service definition. # gRPCのサービス class Service - include GRPC::GenericService self.marshal_class_method = :encode diff --git a/grpc/ruby_client/proto/notification_services_pb.rb b/grpc/ruby_client/proto/notification_services_pb.rb index 17cdc0e..7426d2f 100644 --- a/grpc/ruby_client/proto/notification_services_pb.rb +++ b/grpc/ruby_client/proto/notification_services_pb.rb @@ -1,14 +1,15 @@ +# frozen_string_literal: true + # 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' module Sample module Notifier # The greeting service definition. class Service - include GRPC::GenericService self.marshal_class_method = :encode