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
- #terminate ⇒ 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 = Krakow::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 23 24 25 26 27 |
# File 'lib/basicjrpc/server.rb', line 10 def listen puts "Listening..." while true = @nsq_consumer.pop payload = Oj.load(.body) puts "Processing message #{payload.message_id} #{payload.method_name} #{payload.method_arguments} #{payload.callers}" # Should always return a data object response = @injected_class.send(payload.method_name, *payload.method_arguments) Redis.new(host: "redis").rpush(payload., Oj.dump(response)) .finish end rescue Exception => e .finish terminate raise e end |
#terminate ⇒ Object
29 30 31 |
# File 'lib/basicjrpc/server.rb', line 29 def terminate @nsq_consumer.terminate end |