class AnyCable::Rack::RPC::Client
Attributes
metadata[R]
pool[R]
Public Class Methods
new(host:, size:, timeout:)
click to toggle source
# 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
Public Instance Methods
command(command:, identifier:, connection_identifiers:, data:, headers:, url:, connection_state: nil, state: nil)
click to toggle source
# 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, metadata) end end
connect(headers:, url:)
click to toggle source
# 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, metadata) end end
disconnect(identifiers:, subscriptions:, headers:, url:, state: nil, channels_state: nil)
click to toggle source
# 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, metadata) end end
Private Instance Methods
encode_istate(state)
click to toggle source
We need a string -> string Hash here
# File lib/anycable/rack/rpc/client.rb, line 64 def encode_istate(state) state.transform_values(&:to_json) end