Class: BasicJRPC::Server
- Inherits:
-
Object
- Object
- BasicJRPC::Server
- Defined in:
- lib/basicjrpc/server.rb
Instance Method Summary collapse
-
#initialize(queue, injected_class) ⇒ Server
constructor
A new instance of Server.
- #listen ⇒ Object
Constructor Details
#initialize(queue, injected_class) ⇒ Server
Returns a new instance of Server.
4 5 6 7 8 |
# File 'lib/basicjrpc/server.rb', line 4 def initialize queue, injected_class @injected_class = injected_class @queue = queue @redis = Redis.new(host: "redis") end |
Instance Method Details
#listen ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/basicjrpc/server.rb', line 10 def listen puts "Listening..." while true payload = @redis.blpop(@queue)[1] payload = Oj.load(payload) puts "Processing message #{payload.method_name} #{payload.args}" if BasicJRPC::Config.debug # Should always return a data object response = @injected_class.send(payload.method_name, *payload.args) # Bounce the response back if response is requested @redis.rpush(payload., Oj.dump(response)) if payload.response_requested end end |