Client ancestor class
# File lib/qrack/client.rb, line 16 def initialize(opts = {}) @host = opts[:host] || 'localhost' @user = opts[:user] || 'guest' @pass = opts[:pass] || 'guest' @vhost = opts[:vhost] || '/' @logfile = opts[:logfile] || nil @logging = opts[:logging] || false @ssl = opts[:ssl] || false @verify_ssl = opts[:verify_ssl].nil? || opts[:verify_ssl] @status = :not_connected @frame_max = opts[:frame_max] || 131072 @channel_max = opts[:channel_max] || 0 @heartbeat = opts[:heartbeat] || 0 @connect_timeout = opts[:connect_timeout] || CONNECT_TIMEOUT @logger = nil create_logger if @logging @message_in = false @message_out = false @connecting = false @channels ||= [] # Create channel 0 @channel = create_channel() @exchanges ||= {} @queues ||= {} end
Closes all active communication channels and connection. If an error occurs a Bunny::ProtocolError is raised. If successful, Client.status is set to :not_connected.
:not_connected if successful.
# File lib/qrack/client.rb, line 55 def close # Close all active channels channels.each do |c| c.close if c.open? end # Close connection to AMQP server close_connection # Close TCP Socket close_socket end
# File lib/qrack/client.rb, line 70 def connected? status == :connected end
# File lib/qrack/client.rb, line 74 def connecting? connecting end
# File lib/qrack/client.rb, line 78 def logging=(bool) @logging = bool create_logger if @logging end
# File lib/qrack/client.rb, line 83 def next_payload(options = {}) next_frame(options).payload end
# File lib/qrack/client.rb, line 89 def read(*args) send_command(:read, *args) end
Checks to see whether or not an undeliverable message has been returned as a result of a publish with the :immediate or :mandatory options.
<tt>:timeout => number of seconds (default = 0.1) - The method will wait for a return message until this timeout interval is reached.
{:header => nil, :payload => :no_return, :return_details => nil} if message is not returned before timeout. {:header, :return_details, :payload} if message is returned. :return_details is a hash {:reply_code, :reply_text, :exchange, :routing_key}.
# File lib/qrack/client.rb, line 114 def returned_message(opts = {}) begin frame = next_frame(:timeout => opts[:timeout] || 0.1) rescue Qrack::ClientTimeout return {:header => nil, :payload => :no_return, :return_details => nil} end method = frame.payload header = next_payload # If maximum frame size is smaller than message payload body then message # will have a message header and several message bodies msg = '' while msg.length < header.size msg += next_payload end # Return the message and related info {:header => header, :payload => msg, :return_details => method.arguments} end
Generated with the Darkfish Rdoc Generator 2.