class Synapse::Command::CommandGateway
Simplified interface to the command bus @api public
Attributes
@return [Array<CommandFilter>]
@return [RetryScheduler]
Public Class Methods
@param [CommandBus] command_bus @return [undefined]
# File lib/synapse/command/gateway.rb, line 14 def initialize(command_bus) @command_bus = command_bus @filters = Array.new end
Public Instance Methods
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.
@api public @param [Object] command @return [undefined]
# File lib/synapse/command/gateway.rb, line 27 def send(command) send_with_callback command, CommandCallback.new end
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.
@api public @raise [CommandExecutionError] If an error occured while executing the command @param [Object] command @param [Float] timeout @return [Object] The return value from the command handler
# 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
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.
@api public @param [Object] command @param [CommandCallback] callback @return [undefined]
# File lib/synapse/command/gateway.rb, line 40 def send_with_callback(command, callback) command = process_with_filters(CommandMessage.as_message(command)) if @retry_scheduler callback = RetryingCallback.new callback, command, @retry_scheduler, @command_bus end @command_bus.dispatch_with_callback(command, callback) end
Protected Instance Methods
@param [CommandMessage] command @return [CommandMessage] The message to dispatch
# File lib/synapse/command/gateway.rb, line 71 def process_with_filters(command) @filters.each do |filter| command = filter.filter command end command end