Class: DispatchRider::Publisher
- Inherits:
-
Object
- Object
- DispatchRider::Publisher
- Extended by:
- ConfigurationSupport
- Includes:
- Callbacks::Support
- Defined in:
- lib/dispatch-rider/publisher.rb,
lib/dispatch-rider/publisher/configuration_reader.rb,
lib/dispatch-rider/publisher/configuration_support.rb
Overview
This class takes care of the publishing side of the messaging system.
Defined Under Namespace
Modules: ConfigurationReader, ConfigurationSupport Classes: Base, Configuration, ServiceChannelMapper
Instance Attribute Summary collapse
-
#notification_service_registrar ⇒ Object
readonly
Returns the value of attribute notification_service_registrar.
-
#publishing_destination_registrar ⇒ Object
readonly
Returns the value of attribute publishing_destination_registrar.
-
#service_channel_mapper ⇒ Object
readonly
Returns the value of attribute service_channel_mapper.
-
#sns_channel_registrar ⇒ Object
readonly
Returns the value of attribute sns_channel_registrar.
Instance Method Summary collapse
-
#initialize(configuration = self.class.configuration) ⇒ Publisher
constructor
A new instance of Publisher.
- #publish(message:, destinations:) ⇒ Object
- #register_channel(service, name, options = {}) ⇒ Object
- #register_destination(name, service, channel, options = {}) ⇒ Object
- #register_notification_service(name, options = {}) ⇒ Object
Methods included from ConfigurationSupport
Constructor Details
#initialize(configuration = self.class.configuration) ⇒ Publisher
Returns a new instance of Publisher.
15 16 17 18 19 20 21 |
# File 'lib/dispatch-rider/publisher.rb', line 15 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 |
Instance Attribute Details
#notification_service_registrar ⇒ Object (readonly)
Returns the value of attribute notification_service_registrar.
13 14 15 |
# File 'lib/dispatch-rider/publisher.rb', line 13 def notification_service_registrar @notification_service_registrar end |
#publishing_destination_registrar ⇒ Object (readonly)
Returns the value of attribute publishing_destination_registrar.
13 14 15 |
# File 'lib/dispatch-rider/publisher.rb', line 13 def publishing_destination_registrar @publishing_destination_registrar end |
#service_channel_mapper ⇒ Object (readonly)
Returns the value of attribute service_channel_mapper.
13 14 15 |
# File 'lib/dispatch-rider/publisher.rb', line 13 def service_channel_mapper @service_channel_mapper end |
#sns_channel_registrar ⇒ Object (readonly)
Returns the value of attribute sns_channel_registrar.
13 14 15 |
# File 'lib/dispatch-rider/publisher.rb', line 13 def sns_channel_registrar @sns_channel_registrar end |
Instance Method Details
#publish(message:, destinations:) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/dispatch-rider/publisher.rb', line 40 def publish(message:, destinations:) = { message: (), destinations: destinations } callbacks.invoke(:publish, **) do service_channel_mapper.map(.delete(:destinations)).each do |(service, channels)| notification_service_registrar.fetch(service).publish(**(.merge to: channels)) end end end |
#register_channel(service, name, options = {}) ⇒ Object
34 35 36 37 38 |
# File 'lib/dispatch-rider/publisher.rb', line 34 def register_channel(service, name, = {}) notification_service = notification_service_registrar.fetch(service) notification_service.register(name, ) self end |
#register_destination(name, service, channel, options = {}) ⇒ Object
28 29 30 31 32 |
# File 'lib/dispatch-rider/publisher.rb', line 28 def register_destination(name, service, channel, = {}) register_channel(service, channel, ) publishing_destination_registrar.register(name, :service => service, :channel => channel) self end |
#register_notification_service(name, options = {}) ⇒ Object
23 24 25 26 |
# File 'lib/dispatch-rider/publisher.rb', line 23 def register_notification_service(name, = {}) notification_service_registrar.register(name, ) self end |