@!attribute [rw] logger
@return [Logger] the Sensu logger object.
Discover available transports (Subclasses)
# File lib/sensu/transport/base.rb, line 138 def self.descendants ObjectSpace.each_object(Class).select do |klass| klass < self end end
# File lib/sensu/transport/base.rb, line 17 def initialize @on_error = Proc.new {} @before_reconnect = Proc.new {} @after_reconnect = Proc.new {} end
Alias for acknowledge(). This should be superseded by a proper alias via alias_method in the transport class.
# File lib/sensu/transport/base.rb, line 122 def ack(*args, &callback) acknowledge(*args, &callback) end
Acknowledge the delivery of a message from the transport.
@param info [Hash] message information, eg. contains its id. @yield [info] passes acknowledgment info to an optional callback/block.
# File lib/sensu/transport/base.rb, line 116 def acknowledge(info) yield(info) if block_given? end
Set the after reconnect callback.
@param callback [Proc] called after reconnecting to the
transport.
@return [Proc] the after reconnect callback.
# File lib/sensu/transport/base.rb, line 46 def after_reconnect(&callback) @after_reconnect = callback end
Set the before reconnect callback.
@param callback [Proc] called before attempting to reconnect
to the transport.
@return [Proc] the before reconnect callback.
# File lib/sensu/transport/base.rb, line 37 def before_reconnect(&callback) @before_reconnect = callback end
Close the transport connection.
# File lib/sensu/transport/base.rb, line 68 def close; end
Transport connection setup.
@param options [Hash, String]
# File lib/sensu/transport/base.rb, line 53 def connect(options={}); end
Indicates if connected to the transport.
@return [TrueClass, FalseClass]
# File lib/sensu/transport/base.rb, line 63 def connected? false end
Set the error callback.
@param callback [Proc] called in the event of a transport
error, the exception object should be passed as a parameter.
@return [Proc] the error callback.
# File lib/sensu/transport/base.rb, line 28 def on_error(&callback) @on_error = callback end
Publish a message to the transport.
@param type [Symbol] the transport pipe type, possible values
are: :direct and :fanout.
@param pipe [String] the transport pipe name. @param message [String] the message to be published to the transport. @param options [Hash] the options to publish the message with. @yield [info] passes publish info to an optional callback/block. @yieldparam info [Hash] contains publish information, which
may contain an error object (:error).
# File lib/sensu/transport/base.rb, line 80 def publish(type, pipe, message, options={}) info = {:error => nil} yield(info) if block_given? end
Reconnect to the transport.
@param force [Boolean] the reconnect.
# File lib/sensu/transport/base.rb, line 58 def reconnect(force=false); end
Transport funnel stats, such as message and consumer counts.
@param funnel [String] the transport funnel to get stats for. @param options [Hash] the options to get funnel stats with. @yield [info] passes funnel stats a callback/block. @yieldparam info [Hash] contains funnel stats.
# File lib/sensu/transport/base.rb, line 132 def stats(funnel, options={}) info = {} yield(info) if block_given? end
Subscribe to a transport pipe and/or funnel.
@param type [Symbol] the transport pipe type, possible values
are: :direct and :fanout.
@param pipe [String] the transport pipe name. @param funnel [String] the transport funnel, which may be
connected to multiple pipes.
@param options [Hash] the options to consume messages with. @yield [info, message] passes message info and content to
the consumer callback/block.
@yieldparam info [Hash] contains message information. @yieldparam message [String] message.
# File lib/sensu/transport/base.rb, line 97 def subscribe(type, pipe, funnel=nil, options={}) info = {} message = '' yield(info, message) end
Unsubscribe from all transport pipes and/or funnels.
@yield [info] passes info to an optional callback/block. @yieldparam info [Hash] contains unsubscribe information.
# File lib/sensu/transport/base.rb, line 107 def unsubscribe info = {} yield(info) if block_given? end
Catch transport errors and call the #on_error callback, providing it with the error object as an argument. This method is intended to be applied where necessary, not to be confused with a catch-all. Not all transports will need this.
@yield [] callback/block to execute within a rescue block to
catch transport errors.
# File lib/sensu/transport/base.rb, line 153 def catch_errors begin yield rescue => error @on_error.call(error) end end