Class: RailwayIpc::SingletonPublisher

Inherits:
Sneakers::Publisher
  • Object
show all
Includes:
Singleton
Defined in:
lib/railway_ipc/publisher.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSingletonPublisher

Returns a new instance of SingletonPublisher.



17
18
19
# File 'lib/railway_ipc/publisher.rb', line 17

def initialize
  super(exchange: self.class.exchange_name, exchange_type: :fanout)
end

Class Method Details

.exchange(exchange) ⇒ Object



7
8
9
# File 'lib/railway_ipc/publisher.rb', line 7

def self.exchange(exchange)
  @exchange_name = exchange
end

.exchange_nameObject



11
12
13
14
15
# File 'lib/railway_ipc/publisher.rb', line 11

def self.exchange_name
  raise 'Subclass must set the exchange' unless @exchange_name

  @exchange_name
end

Instance Method Details

#publish(message, published_message_store = RailwayIpc::PublishedMessage) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/railway_ipc/publisher.rb', line 21

def publish(message, published_message_store=RailwayIpc::PublishedMessage)
  RailwayIpc.logger.warn('DEPRECATED: Use new PublisherInstance class', log_message_options)
  ensure_message_uuid(message)
  ensure_correlation_id(message)
  RailwayIpc.logger.info('Publishing message', log_message_options(message))
  result = super(RailwayIpc::Rabbitmq::Payload.encode(message))
  published_message_store.store_message(self.class.exchange_name, message)
  result
rescue RailwayIpc::InvalidProtobuf => e
  RailwayIpc.logger.error('Invalid protobuf', log_message_options(message))
  raise e
end