Class: Moleculer::Transporters::Redis::Subscriber
- Inherits:
-
Object
- Object
- Moleculer::Transporters::Redis::Subscriber
- Defined in:
- lib/moleculer/transporters/redis.rb
Overview
Represents the subscriber connection
Defined Under Namespace
Classes: Subscription
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect ⇒ Object
-
#initialize(config) ⇒ Subscriber
constructor
A new instance of Subscriber.
- #started? ⇒ Boolean
- #subscribe(channel, &block) ⇒ Object
Constructor Details
#initialize(config) ⇒ Subscriber
Returns a new instance of Subscriber.
155 156 157 158 159 160 161 |
# File 'lib/moleculer/transporters/redis.rb', line 155 def initialize(config) @config = config @uri = config.transporter @logger = config.logger.get_child("[REDIS.TRANSPORTER]") @subscriptions = Concurrent::Array.new @started = false end |
Instance Method Details
#connect ⇒ Object
179 180 181 182 183 |
# File 'lib/moleculer/transporters/redis.rb', line 179 def connect @logger.debug "connecting subscriptions" @subscriptions.each(&:connect) @started = true end |
#disconnect ⇒ Object
174 175 176 177 |
# File 'lib/moleculer/transporters/redis.rb', line 174 def disconnect @logger.debug "disconnecting subscriptions" @subscriptions.each(&:disconnect) end |
#started? ⇒ Boolean
185 186 187 |
# File 'lib/moleculer/transporters/redis.rb', line 185 def started? @started end |
#subscribe(channel, &block) ⇒ Object
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/moleculer/transporters/redis.rb', line 163 def subscribe(channel, &block) @logger.debug "subscribing to channel '#{channel}'" @subscriptions << Subscription.new( channel: channel, block: block, config: @config, ) @subscriptions.last.connect if started? end |