Class: Yrpc::Interceptors::ClientInterceptor

Inherits:
GRPC::ClientInterceptor
  • Object
show all
Defined in:
lib/yrpc/interceptors/client_interceptor.rb

Overview

Intercepts outbound client requests to provide a unified interface and request context

Instance Method Summary collapse

Instance Method Details

#bidi_streamer(requests: nil, call: nil, method: nil, metadata: nil) ⇒ Object

Call the interceptor from the bidi_streamer call

Parameters:

  • requests (Enumerable) (defaults to: nil)

    An enumerable of requests being sent

  • call (GRPC::ActiveCall) (defaults to: nil)

    The GRPC ActiveCall object

  • method (Method) (defaults to: nil)

    The method being called

  • metadata (Hash) (defaults to: nil)

    A hash of outgoing metadata



90
91
92
93
94
# File 'lib/yrpc/interceptors/client_interceptor.rb', line 90

def bidi_streamer(requests: nil, call: nil, method: nil, metadata: nil)
  rc = Yrpc::Outbound::RequestContext.new(type: :bidi_streamer, requests: requests, call: call, method: method, metadata: )
  call(request_context: rc)
  yield
end

#call(request_context:) ⇒ Object

Handles interception of outbound calls. Implement this in your derivative interceptor implementation.

Parameters:

Returns:

  • (Object)

    This method must return the response from the yielded block



30
31
32
33
# File 'lib/yrpc/interceptors/client_interceptor.rb', line 30

def call(request_context:)
  Yrpc.logger "Logging client interceptor for request: #{request_context.method}"
  yield
end

#client_streamer(requests: nil, call: nil, method: nil, metadata: nil) ⇒ Object

Call the interceptor from the client_streamer call

Parameters:

  • requests (Enumerable) (defaults to: nil)

    An enumerable of requests being sent

  • call (GRPC::ActiveCall) (defaults to: nil)

    The GRPC ActiveCall object

  • method (Method) (defaults to: nil)

    The method being called

  • metadata (Hash) (defaults to: nil)

    A hash of outgoing metadata

Returns:

  • (Object)

    The response message



60
61
62
63
64
65
# File 'lib/yrpc/interceptors/client_interceptor.rb', line 60

def client_streamer(requests: nil, call: nil, method: nil, metadata: nil)
  rc = Yrpc::Outbound::RequestContext.new(type: :client_streamer, requests: requests, call: call, method: method, metadata: )
  call(request_context: rc)
  matadata= .merge!(rc.)
  yield
end

#request_response(request: nil, call: nil, method: nil, metadata: nil) ⇒ Object

Call the interceptor from the request_response call

Parameters:

  • request (Object) (defaults to: nil)

    The request being sent

  • call (GRPC::ActiveCall) (defaults to: nil)

    The GRPC ActiveCall object

  • method (Method) (defaults to: nil)

    The method being called

  • metadata (Hash) (defaults to: nil)

    A hash of outgoing metadata

Returns:

  • (Object)

    The response message



44
45
46
47
48
49
# File 'lib/yrpc/interceptors/client_interceptor.rb', line 44

def request_response(request: nil, call: nil, method: nil, metadata: nil)
  rc = Yrpc::Outbound::RequestContext.new(type: :request_response, requests: [request], call: call, method: method, metadata: )
  call(request_context: rc)
  matadata= .merge!(rc.)
  yield
end

#server_streamer(request: nil, call: nil, method: nil, metadata: nil) ⇒ Object

Call the interceptor from the server_streamer call

Parameters:

  • request (Object) (defaults to: nil)

    The request being sent

  • call (GRPC::ActiveCall) (defaults to: nil)

    The GRPC ActiveCall object

  • method (Method) (defaults to: nil)

    The method being called

  • metadata (Hash) (defaults to: nil)

    A hash of outgoing metadata

Returns:

  • (Object)

    The response message



76
77
78
79
80
# File 'lib/yrpc/interceptors/client_interceptor.rb', line 76

def server_streamer(request: nil, call: nil, method: nil, metadata: nil)
  rc = Yrpc::Outbound::RequestContext.new(type: :server_streamer, requests: [request], call: call, method: method, metadata: )
  call(request_context: rc)
  yield
end