Class: GrpcKit::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/grpc_kit/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(sock, authority: nil, interceptors: [], timeout: nil, max_receive_message_size: nil, max_send_message_size: nil) ⇒ Client

Returns a new instance of Client.

Parameters:

  • sock (TCPSocket)
  • authority (nil, String) (defaults to: nil)
  • interceptors (Array<GrpcKit::Grpc::ClientInterceptor>) (defaults to: [])

    list of interceptors

  • timeout (nil, Integer, String) (defaults to: nil)
  • max_receive_message_size (Integer, nil) (defaults to: nil)

    Specify the default maximum size of inbound message in bytes. Default to 4MB.

  • max_send_message_size (Integer, nil) (defaults to: nil)

    Specify the default maximum size of outbound message in bytes. Default to 4MB.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/grpc_kit/client.rb', line 17

def initialize(sock, authority: nil, interceptors: [], timeout: nil, max_receive_message_size: nil, max_send_message_size: nil)
  @sock = sock
  @authority =
    if authority
      authority
    else
      addr = sock.addr
      "#{addr[3]}:#{addr[1]}"
    end

  @timeout = timeout && GrpcKit::GrpcTime.new(timeout)

  # Defined at GrpcKit::Grpc::Dsl#.rpc_stub_class
  build_rpcs(
    interceptors,
    max_receive_message_size: max_receive_message_size,
    max_send_message_size: max_send_message_size,
  )
end

Instance Method Details

#bidi_streamer(rpc, _requests, **opts) ⇒ Object

Parameters:



63
64
65
66
# File 'lib/grpc_kit/client.rb', line 63

def bidi_streamer(rpc, _requests, **opts)
  GrpcKit.logger.debug('Calling bidi_streamer')
  do_request(rpc, nil, **opts)
end

#client_streamer(rpc, **opts) ⇒ Object

Parameters:



47
48
49
50
# File 'lib/grpc_kit/client.rb', line 47

def client_streamer(rpc, **opts)
  GrpcKit.logger.debug('Calling client_streamer')
  do_request(rpc, nil, **opts)
end

#request_response(rpc, request, **opts) ⇒ Object

Parameters:



40
41
42
43
# File 'lib/grpc_kit/client.rb', line 40

def request_response(rpc, request, **opts)
  GrpcKit.logger.debug('Calling request_respose')
  do_request(rpc, request, **opts)
end

#server_streamer(rpc, request, **opts) ⇒ Object

Parameters:



55
56
57
58
# File 'lib/grpc_kit/client.rb', line 55

def server_streamer(rpc, request, **opts)
  GrpcKit.logger.debug('Calling server_streamer')
  do_request(rpc, request, **opts)
end