Class: Gruf::Interceptors::ClientInterceptor

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

Overview

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

Instance Method Summary collapse

Methods included from Loggable

#logger

Instance Method Details

#bidi_streamer(requests: nil, call: nil, method: nil, metadata: nil, &block) ⇒ 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



105
106
107
108
109
110
111
112
113
114
# File 'lib/gruf/interceptors/client_interceptor.rb', line 105

def bidi_streamer(requests: nil, call: nil, method: nil, metadata: nil, &block)
  rc = Gruf::Outbound::RequestContext.new(
    type: :bidi_streamer,
    requests: requests,
    call: call,
    method: method,
    metadata: 
  )
  call(request_context: rc, &block)
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



32
33
34
35
# File 'lib/gruf/interceptors/client_interceptor.rb', line 32

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

#client_streamer(requests: nil, call: nil, method: nil, metadata: nil, &block) ⇒ 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



66
67
68
69
70
71
72
73
74
75
# File 'lib/gruf/interceptors/client_interceptor.rb', line 66

def client_streamer(requests: nil, call: nil, method: nil, metadata: nil, &block)
  rc = Gruf::Outbound::RequestContext.new(
    type: :client_streamer,
    requests: requests,
    call: call,
    method: method,
    metadata: 
  )
  call(request_context: rc, &block)
end

#request_response(request: nil, call: nil, method: nil, metadata: nil, &block) ⇒ 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



46
47
48
49
50
51
52
53
54
55
# File 'lib/gruf/interceptors/client_interceptor.rb', line 46

def request_response(request: nil, call: nil, method: nil, metadata: nil, &block)
  rc = Gruf::Outbound::RequestContext.new(
    type: :request_response,
    requests: [request],
    call: call,
    method: method,
    metadata: 
  )
  call(request_context: rc, &block)
end

#server_streamer(request: nil, call: nil, method: nil, metadata: nil, &block) ⇒ 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



86
87
88
89
90
91
92
93
94
95
# File 'lib/gruf/interceptors/client_interceptor.rb', line 86

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