Class: RemoteService::Queue

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/remote_service/queue.rb

Instance Method Summary collapse

Instance Method Details

#connect(brokers, &block) ⇒ Object



9
10
11
12
# File 'lib/remote_service/queue.rb', line 9

def connect(brokers, &block)
  @conn = RemoteService::Connector::Nats.new(brokers)
  @conn.start(&block)
end

#publish(queue, payload) ⇒ Object



31
32
33
# File 'lib/remote_service/queue.rb', line 31

def publish(queue, payload)
  @conn.publish(queue, encode(payload))
end

#request(queue, payload) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/remote_service/queue.rb', line 20

def request(queue, payload)
  RemoteService.logger.debug "REQUEST - SERVICE:[#{queue}] PAYLOAD:[#{payload}]"
  sent_at = Time.now.utc
  @conn.request(queue, encode(payload)) do |response|
    data = decode(response)
    response_time = (Time.now.utc - sent_at)*1000
    RemoteService.logger.debug "RESPONSE - SERVICE:[#{queue}] PAYLOAD:[#{data}] TIME:[#{response_time}ms]"
    yield(data)
  end
end

#service(service_handler, workers = 16) ⇒ Object



14
15
16
17
18
# File 'lib/remote_service/queue.rb', line 14

def service(service_handler, workers=16)
  @service_handler = service_handler
  @workers = workers
  start_service_subscriber
end

#stopObject



35
36
37
# File 'lib/remote_service/queue.rb', line 35

def stop
  @conn.stop
end