Class: Pheromone::Messaging::MessageDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/pheromone/messaging/message_dispatcher.rb

Defined Under Namespace

Classes: NoSpecifiedProcessor

Instance Method Summary collapse

Constructor Details

#initialize(message_parameters:, dispatch_method:) ⇒ MessageDispatcher

Returns a new instance of MessageDispatcher.



14
15
16
17
# File 'lib/pheromone/messaging/message_dispatcher.rb', line 14

def initialize(message_parameters:, dispatch_method:)
  @message_parameters = message_parameters
  @dispatch_method = dispatch_method
end

Instance Method Details

#dispatchObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pheromone/messaging/message_dispatcher.rb', line 19

def dispatch
  return unless Pheromone.enabled?
  if @dispatch_method == :sync
    Message.new(
      message_body.merge!(
        encoder: @message_parameters[:encoder],
        message_format: @message_parameters[:message_format]
      )
    ).send!
  elsif @dispatch_method == :async
    send_message_asynchronously
  end
end