-
Notifications
You must be signed in to change notification settings - Fork 0
/
routeguide_client.rb
40 lines (31 loc) · 1011 Bytes
/
routeguide_client.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true
$LOAD_PATH.unshift File.expand_path('./routeguide')
require 'socket'
require 'grpc_kit'
require 'pry'
require 'json'
require 'routeguide_services_pb'
RESOURCE_PATH = './examples/routeguide/routeguide.json'
HOST = 'localhost'
PORT = 50051
def list_features(stub)
GRPC.logger.info('===== list_features =====')
rect = Routeguide::Rectangle.new(
lo: Routeguide::Point.new(latitude: 400_000_000, longitude: -750_000_000),
hi: Routeguide::Point.new(latitude: 420_000_000, longitude: -730_000_000),
)
stream = stub.list_features(rect)
stream.each do |r|
GRPC.logger.info("Found #{r.name} at #{r.location.inspect}")
end
end
opts = {}
if ENV['GRPC_INTERCEPTOR']
require_relative 'interceptors/client_logging_interceptor'
opts[:interceptors] = [LoggingInterceptor.new]
elsif ENV['GRPC_TIMEOUT']
opts[:timeout] = Integer(ENV['GRPC_TIMEOUT'])
end
sock = TCPSocket.new(HOST, PORT)
stub = Routeguide::RouteGuide::Stub.new(sock, **opts)
list_features(stub)