Class: AnyCable::Rack::RPC::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/anycable/rack/rpc/client.rb

Overview

AnyCable RPC client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, size:, timeout:) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
# File 'lib/anycable/rack/rpc/client.rb', line 13

def initialize(host:, size:, timeout:)
  @pool = ConnectionPool.new(size: size, timeout: timeout) do
    AnyCable::GRPC::Service.rpc_stub_class.new(host, :this_channel_is_insecure)
  end
  @metadata = {metadata: {"protov" => "v1"}}.freeze
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



11
12
13
# File 'lib/anycable/rack/rpc/client.rb', line 11

def 
  @metadata
end

#poolObject (readonly)

Returns the value of attribute pool.



11
12
13
# File 'lib/anycable/rack/rpc/client.rb', line 11

def pool
  @pool
end

Instance Method Details

#command(command:, identifier:, connection_identifiers:, data:, headers:, url:, connection_state: nil, state: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/anycable/rack/rpc/client.rb', line 27

def command(command:, identifier:, connection_identifiers:, data:, headers:, url:, connection_state: nil, state: nil)
  message = CommandMessage.new(
    command: command,
    identifier: identifier,
    connection_identifiers: connection_identifiers,
    data: data,
    env: Env.new(
      headers: headers,
      url: url,
      cstate: connection_state,
      istate: state
    )
  )
  pool.with do |stub|
    stub.command(message, )
  end
end

#connect(headers:, url:) ⇒ Object



20
21
22
23
24
25
# File 'lib/anycable/rack/rpc/client.rb', line 20

def connect(headers:, url:)
  request = ConnectionRequest.new(env: Env.new(headers: headers, url: url))
  pool.with do |stub|
    stub.connect(request, )
  end
end

#disconnect(identifiers:, subscriptions:, headers:, url:, state: nil, channels_state: nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/anycable/rack/rpc/client.rb', line 45

def disconnect(identifiers:, subscriptions:, headers:, url:, state: nil, channels_state: nil)
  request = DisconnectRequest.new(
    identifiers: identifiers,
    subscriptions: subscriptions,
    env: Env.new(
      headers: headers,
      url: url,
      cstate: state,
      istate: encode_istate(channels_state)
    )
  )
  pool.with do |stub|
    stub.disconnect(request, )
  end
end