Class: RuoteNATS::CommandReceiver

Inherits:
Object
  • Object
show all
Defined in:
lib/ruote-nats/command_receiver.rb

Instance Method Summary collapse

Instance Method Details

#start(queue_name = 'remote.command') ⇒ Object

Starts to subscribe command queue.

Parameters:

  • queue_name (String) (defaults to: 'remote.command')


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ruote-nats/command_receiver.rb', line 7

def start(queue_name = 'remote.command')
  NATS.subscribe(queue_name, queue: queue_name, max: 1) do |message, reply|
    NATS.publish(reply, 'ACCEPT') do
      unpacked = MessagePack.unpack(message)
      workitem = Ruote::Workitem.new(unpacked)

      RuoteNATS.logger.info do
        "(#{workitem.sid}) receive command: #{lookup_executor(workitem)} (#{workitem.lookup('params')})"
      end

      dispatch(workitem)
      publish_reply(workitem)
    end
  end
end