class Qrack::Client

Client ancestor class

Constants

CONNECT_TIMEOUT
RETRY_DELAY

Attributes

channel[RW]
channels[RW]
connecting[RW]
exchanges[RW]
heartbeat[R]
host[R]
logfile[RW]
logging[R]
message_in[RW]
message_out[RW]
port[R]
queues[RW]
spec[R]
status[R]
vhost[R]

Public Instance Methods

close() click to toggle source

DESCRIPTION:

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.

RETURNS:

: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
Also aliased as: stop
connected?() click to toggle source
# File lib/qrack/client.rb, line 70
def connected?
        status == :connected
end
connecting?() click to toggle source
# File lib/qrack/client.rb, line 74
def connecting?
        connecting
end
logging=(bool) click to toggle source
# File lib/qrack/client.rb, line 78
def logging=(bool)
        @logging = bool
        create_logger if @logging
end
next_method(options = {}) click to toggle source
Alias for: next_payload
next_payload(options = {}) click to toggle source
# File lib/qrack/client.rb, line 83
def next_payload(options = {})
  next_frame(options).payload
end
Also aliased as: next_method
read(*args) click to toggle source
# File lib/qrack/client.rb, line 89
def read(*args)
  send_command(:read, *args)
end
returned_message(opts = {}) click to toggle source

DESCRIPTION:

Checks to see whether or not an undeliverable message has been returned as a result of a publish with the :immediate or :mandatory options.

OPTIONS:

  • <tt>:timeout => number of seconds (default = 0.1) - The method will wait for a return message until this timeout interval is reached.

RETURNS:

{: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
stop() click to toggle source
Alias for: close
switch_channel(chann) click to toggle source
# File lib/qrack/client.rb, line 136
def switch_channel(chann)
        if (0...channels.size).include? chann
                @channel = channels[chann]
                chann
        else
                raise RuntimeError, "Invalid channel number - #{chann}"
        end
end
write(*args) click to toggle source
# File lib/qrack/client.rb, line 145
            def write(*args)
  send_command(:write, *args)
end

Public Class Methods

new(opts = {}) click to toggle source
# 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