Module: Synapse::Wiring::MessageWiring::ClassMethods

Defined in:
lib/synapse/wiring/message_wiring.rb

Instance Method Summary collapse

Instance Method Details

#wire(type, *args, &block) ⇒ undefined

Wires a message handler to messages with payload of the given type

Certain components that use message handling have different options that can be set on wires, like wiring processes.

Examples:

wire CashWithdrawnEvent do |event|
  # do something with the event
end
wire CashWithdrawnEvent :to => :on_withdraw

def on_withdraw(event)
  # do something with the event
end
wire SellTransactionStartedEvent, :start => true, :correlate => :transaction_id do
  # do something with the event
end

Parameters:

  • type (Class)
  • args (Object...)
  • block (Proc)

Returns:

  • (undefined)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/synapse/wiring/message_wiring.rb', line 48

def wire(type, *args, &block)
  options = args.extract_options!

  to = options.delete :to
  unless to
    unless block
      raise ArgumentError, 'Expected block or option :to'
    end

    to = block
  end

  wire = Wire.new type, options, to

  self.wire_registry.register wire
end