Class: Moleculer::Transporters::Redis::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/moleculer/transporters/redis.rb

Overview

Represents the publisher connection

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Publisher

Returns a new instance of Publisher.



15
16
17
18
19
# File 'lib/moleculer/transporters/redis.rb', line 15

def initialize(config)
  @uri        = config.transporter
  @logger     = config.logger.get_child("[REDIS.TRANSPORTER.PUBLISHER]")
  @serializer = Serializers.for(config.serializer).new(config)
end

Instance Method Details

#connectObject

Connects to redis



31
32
33
34
# File 'lib/moleculer/transporters/redis.rb', line 31

def connect
  @logger.debug "connecting publisher client on '#{@uri}'"
  connection
end

#disconnectObject

Disconnects from redis



38
39
40
41
# File 'lib/moleculer/transporters/redis.rb', line 38

def disconnect
  @logger.debug "disconnecting publisher client"
  connection.disconnect!
end

#publish(packet) ⇒ Object

Publishes the packet to the packet's topic



23
24
25
26
27
# File 'lib/moleculer/transporters/redis.rb', line 23

def publish(packet)
  topic = packet.topic
  @logger.debug "publishing packet to '#{topic}'", packet.to_h
  connection.publish(topic, @serializer.serialize(packet))
end