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 @nsq_consumer = Nsq::Consumer.new(nsqlookupd: 'dockerlb:4161', topic: @queue, channel: 'server') end |
Instance Method Details
#listen ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/basicjrpc/server.rb', line 10 def listen puts "Listening..." while true payload = Oj.load(@nsq_consumer.pop) puts "Processing message #{payload.method_name} #{payload.method_arguments}" # Should always return a data object response = @injected_class.send(payload.method_name, *payload.method_arguments) # Bounce the response back if response is requested Nsq::Producer.new(nsqd: 'dockerlb:4150', topic: payload.).write(Oj.dump(response)) if payload.response end end |