lib/moleculer/transporters/fake.rb in moleculer-0.2.0 vs lib/moleculer/transporters/fake.rb in moleculer-0.3.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require_relative "base"
module Moleculer
module Transporters
##
@@ -9,17 +11,21 @@
def initialize(config)
super(config)
# in this case we want to use a class var as this needs to behave like a singleton to mimic how a global
# transporter functions
@@subscriptions ||= {} # rubocop:disable Style/ClassVars
+ @logger = config.logger.get_child("[FAKE.TRANSPORTER]")
end
def subscribe(channel, &block)
- @@subscriptions[channel] = block
+ @@subscriptions[channel] ||= []
+ @@subscriptions[channel] << block
end
def publish(packet)
- @@subscriptions[packet.topic].call(packet)
+ @logger.debug "publishing packet to '#{packet.topic}'", packet.to_h
+ @logger.debug "processing #{@@subscriptions[packet.topic].length} callbacks for '#{packet.topic}'"
+ @@subscriptions[packet.topic].each { |c| c.call(packet) }
end
def start
true
end