Following the Redis Pub/Sub
this works fine and i can publish messages in any class using
$redis.publish 'channel', { object: @object.id }
using redis-cli > MONITOR
, I can verify that this request was published correctly
[0 127.0.0.1:64192] "publish" "channel" "{:object=>\"5331d541f4eec77185000003\" }"
the problem starts when I add a subscriber block to that channel in other class (listener class) like the following
class OtherClass
$redis.subscribe('channel') do |payload|
p payload
end
end
in redis-cli > MONITOR
, shows also that the listener is subscribed correctly
[0 127.0.0.1:52930] "subscribe" "channel"
the problem is that when i add the subscriber listener class to the same rails app... it stop working cause the OtherClass
listens to the redis server and halt the execution of any other code... it just sit there listening.
so is there a way to make a messaging bus with redis on the same rails app... so that events are published from some classes or service objects and there are listeners for specific channels to act upon receiving events in the background.
i know that i might use sidekiq or any other background worker to do this job... but after a while the background workers became messy and unmaintainable.
#<Redis::Subscription:0x007f8831620578 @callbacks={}>
and doesn't respond further... i suspect that the problem is inOtherClass
cause i listen to redis via code block... not sure if that is correct or not.