Class: Synapse::Command::CommandGateway
- Inherits:
-
Object
- Object
- Synapse::Command::CommandGateway
- Defined in:
- lib/synapse/command/gateway.rb
Overview
Simplified interface to the command bus
Instance Attribute Summary collapse
Instance Method Summary collapse
- #initialize(command_bus) ⇒ undefined constructor
-
#send(command) ⇒ undefined
Fire and forget method of sending a command to the command bus.
-
#send_and_wait(command, timeout = nil) ⇒ Object
Sends the given command and blocks indefinitely until the result of the execution is provided, the timeout is created or the thread is interrupted.
-
#send_with_callback(command, callback) ⇒ undefined
Sends the given command.
Constructor Details
#initialize(command_bus) ⇒ undefined
14 15 16 17 |
# File 'lib/synapse/command/gateway.rb', line 14 def initialize(command_bus) @command_bus = command_bus @filters = Array.new end |
Instance Attribute Details
#filters ⇒ Array (readonly)
7 8 9 |
# File 'lib/synapse/command/gateway.rb', line 7 def filters @filters end |
#retry_scheduler ⇒ RetryScheduler
10 11 12 |
# File 'lib/synapse/command/gateway.rb', line 10 def retry_scheduler @retry_scheduler end |
Instance Method Details
#send(command) ⇒ undefined
Fire and forget method of sending a command to the command bus
If the given command is a bare object, it will be wrapped in a command message before being dispatched on the command bus.
27 28 29 |
# File 'lib/synapse/command/gateway.rb', line 27 def send(command) send_with_callback command, CommandCallback.new end |
#send_and_wait(command, timeout = nil) ⇒ Object
Sends the given command and blocks indefinitely until the result of the execution is provided, the timeout is created or the thread is interrupted.
If the given command is a bare object, it will be wrapped in a command message before being dispatched on the command bus.
61 62 63 64 65 |
# File 'lib/synapse/command/gateway.rb', line 61 def send_and_wait(command, timeout = nil) callback = FutureCallback.new send_with_callback command, callback callback.result timeout end |
#send_with_callback(command, callback) ⇒ undefined
Sends the given command
If the given command is a bare object, it will be wrapped in a command message before being dispatched on the command bus.
40 41 42 43 44 45 46 47 48 |
# File 'lib/synapse/command/gateway.rb', line 40 def send_with_callback(command, callback) command = process_with_filters(CommandMessage.(command)) if @retry_scheduler callback = RetryingCallback.new callback, command, @retry_scheduler, @command_bus end @command_bus.dispatch_with_callback(command, callback) end |