Class: Moleculer::Transporters::Fake
- Defined in:
- lib/moleculer/transporters/fake.rb
Overview
The fake transporter is designed to be used in testing. It is simply an in memory queue and should not be used in production.
Instance Method Summary collapse
-
#initialize(config) ⇒ Fake
constructor
A new instance of Fake.
- #publish(packet) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #subscribe(channel, &block) ⇒ Object
Constructor Details
#initialize(config) ⇒ Fake
Returns a new instance of Fake.
11 12 13 14 15 16 17 |
# File 'lib/moleculer/transporters/fake.rb', line 11 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 |
Instance Method Details
#publish(packet) ⇒ Object
24 25 26 27 28 |
# File 'lib/moleculer/transporters/fake.rb', line 24 def publish(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 |
#start ⇒ Object
30 31 32 |
# File 'lib/moleculer/transporters/fake.rb', line 30 def start true end |
#stop ⇒ Object
34 35 36 |
# File 'lib/moleculer/transporters/fake.rb', line 34 def stop true end |
#subscribe(channel, &block) ⇒ Object
19 20 21 22 |
# File 'lib/moleculer/transporters/fake.rb', line 19 def subscribe(channel, &block) @@subscriptions[channel] ||= [] @@subscriptions[channel] << block end |