Class: BasicJRPC::Server

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

Instance Method Summary collapse

Constructor Details

#initialize(queue, injected_class) ⇒ Server

Returns a new instance of Server.



37
38
39
40
41
# File 'lib/basicjrpc.rb', line 37

def initialize queue, injected_class
  @injected_class = injected_class
  @queue = queue
  @redis = Redis.new
end

Instance Method Details

#listenObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/basicjrpc.rb', line 43

def listen
  puts "Listening..."
  while true
    payload = @redis.blpop(@queue)[1]
    payload = Oj.load(payload)

    # Should always return a data object
    response = @injected_class.send(payload.method_name, *payload.args)
      
    # Bounce the response back
    @redis.rpush(payload.message_id, Oj.dump(response))
  end
end