Class: Alondra::AsyncMessageQueueClient

Inherits:
MessageQueueClient show all
Defined in:
lib/alondra/message_queue_client.rb

Instance Method Summary collapse

Methods inherited from MessageQueueClient

async_instance, instance, push, sync_instance

Instance Method Details

#contextObject



48
49
50
# File 'lib/alondra/message_queue_client.rb', line 48

def context
  @context ||= EM::ZeroMQ::Context.new(1)
end

#push_socketObject



40
41
42
43
44
45
46
# File 'lib/alondra/message_queue_client.rb', line 40

def push_socket
  @push_socket ||= begin
    push_socket = context.socket(ZMQ::PUSH)
    push_socket.connect(Alondra.config.queue_socket)
    push_socket
  end
end

#send_message(message) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/alondra/message_queue_client.rb', line 30

def send_message(message)
  EM.schedule do
    begin
      push_socket.send_msg(message.to_json)
    rescue Exception => ex
      Log.error "Exception while sending message to message queue: #{ex.message}"
    end
  end
end