My setup is as follows: 1 Microservice that receives a request and writes a message in the queue(nsq) and a second microservice that must read the messages in the queue and do something based on them.
I am new to the nsq concept in ruby on rails. I have installed the nsq from here: http://nsq.io/overview/quick_start.html. I have also used this gem to facilitate pushing messages: https://github.com/wistia/nsq-ruby.
I have been able to queue the message. This part was easy enough.
Question:
How do I always listen in the 2nd microservice to figure out when something was pushed so I can consume it?
This is how I push messages:
require 'nsq'
class NsqService
attr_accessor :producer, :topic
def initialize(topic)
@topic = topic
@producer = producer
end
def publish(message)
producer.write(message)
end
private
def producer(nsqd='127.0.0.1:4150')
Nsq::Producer.new(
nsqd: nsqd,
topic: @topic
)
end
end