class DispatchRider::Publisher
This class takes care of the publishing side of the messaging system.
Attributes
notification_service_registrar[R]
publishing_destination_registrar[R]
service_channel_mapper[R]
sns_channel_registrar[R]
Public Class Methods
new(configuration = self.class.configuration)
click to toggle source
# File lib/dispatch-rider/publisher.rb, line 13 def initialize(configuration = self.class.configuration) @notification_service_registrar = DispatchRider::Registrars::NotificationService.new @publishing_destination_registrar = DispatchRider::Registrars::PublishingDestination.new @service_channel_mapper = ServiceChannelMapper.new(publishing_destination_registrar) ConfigurationReader.load_config(configuration, self) end
Public Instance Methods
publish(original_options = {})
click to toggle source
@param [Hash] original_options should contain `:destinations` and `:message` keys
# File lib/dispatch-rider/publisher.rb, line 39 def publish(original_options = {}) options = build_publish_options(original_options) callbacks.invoke(:publish, options) do service_channel_mapper.map(options.delete(:destinations)).each do |(service, channels)| notification_service_registrar.fetch(service).publish(options.merge to: channels) end end end
register_channel(service, name, options = {})
click to toggle source
# File lib/dispatch-rider/publisher.rb, line 32 def register_channel(service, name, options = {}) notification_service = notification_service_registrar.fetch(service) notification_service.register(name, options) self end
register_destination(name, service, channel, options = {})
click to toggle source
# File lib/dispatch-rider/publisher.rb, line 26 def register_destination(name, service, channel, options = {}) register_channel(service, channel, options) publishing_destination_registrar.register(name, :service => service, :channel => channel) self end
register_notification_service(name, options = {})
click to toggle source
# File lib/dispatch-rider/publisher.rb, line 21 def register_notification_service(name, options = {}) notification_service_registrar.register(name, options) self end
Private Instance Methods
build_message(attributes)
click to toggle source
# File lib/dispatch-rider/publisher.rb, line 55 def build_message(attributes) DispatchRider::Message.new(attributes).tap do |message| message.body[:guid] ||= generate_new_message_id end end
build_publish_options(message:, destinations:)
click to toggle source
# File lib/dispatch-rider/publisher.rb, line 51 def build_publish_options(message:, destinations:) { message: build_message(message), destinations: destinations } end
generate_new_message_id()
click to toggle source
# File lib/dispatch-rider/publisher.rb, line 61 def generate_new_message_id if DispatchRider.config.debug DispatchRider::Debug::PUBLISHER_MESSAGE_GUID else SecureRandom.uuid end end