Class: SGS::RPCClient

Inherits:
Object
  • Object
show all
Defined in:
lib/sgs/rpc.rb

Instance Method Summary collapse

Constructor Details

#initialize(channel) ⇒ RPCClient

Returns a new instance of RPCClient.



38
39
40
# File 'lib/sgs/rpc.rb', line 38

def initialize(channel)
  @channel = channel.to_s
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sgs/rpc.rb', line 42

def method_missing(name, *args)
  uuid = SecureRandom.uuid
  request = {
    'id' => uuid,
    'jsonrpc' => '2.0',
    'method' => name,
    'params' => args
  }
  SGS::RedisBase.redis.lpush(@channel, request.to_msgpack)
  channel, response = SGS::RedisBase.redis.brpop(uuid, timeout=60)
  MessagePack.unpack(response)['result']
end