Module: Bunny

Defined in:
lib/bunny.rb,
lib/bunny/queue.rb,
lib/bunny/socket.rb,
lib/bunny/socket.rb,
lib/bunny/channel.rb,
lib/bunny/framing.rb,
lib/bunny/session.rb,
lib/bunny/timeout.rb,
lib/bunny/version.rb,
lib/bunny/consumer.rb,
lib/bunny/exchange.rb,
lib/bunny/test_kit.rb,
lib/bunny/timestamp.rb,
lib/bunny/transport.rb,
lib/bunny/exceptions.rb,
lib/bunny/ssl_socket.rb,
lib/bunny/ssl_socket.rb,
lib/bunny/reader_loop.rb,
lib/bunny/return_info.rb,
lib/bunny/cruby/socket.rb,
lib/bunny/get_response.rb,
lib/bunny/jruby/socket.rb,
lib/bunny/delivery_info.rb,
lib/bunny/cruby/ssl_socket.rb,
lib/bunny/heartbeat_sender.rb,
lib/bunny/jruby/ssl_socket.rb,
lib/bunny/consumer_work_pool.rb,
lib/bunny/message_properties.rb,
lib/bunny/channel_id_allocator.rb,
lib/bunny/concurrent/condition.rb,
lib/bunny/consumer_tag_generator.rb,
lib/bunny/versioned_delivery_tag.rb,
lib/bunny/concurrent/atomic_fixnum.rb,
lib/bunny/concurrent/continuation_queue.rb,
lib/bunny/authentication/credentials_encoder.rb,
lib/bunny/concurrent/synchronized_sorted_set.rb,
lib/bunny/concurrent/linked_continuation_queue.rb,
lib/bunny/authentication/plain_mechanism_encoder.rb,
lib/bunny/authentication/external_mechanism_encoder.rb

Overview

Bunny is a RabbitMQ client that focuses on ease of use.

Defined Under Namespace

Modules: Authentication, Concurrent, Framing, JRuby, Socket Classes: AccessRefused, AuthenticationFailureError, BadLengthError, Channel, ChannelAlreadyClosed, ChannelError, ChannelIdAllocator, ChannelLevelException, ClientTimeout, CommandInvalid, ConnectionAlreadyClosed, ConnectionClosedError, ConnectionForced, ConnectionLevelException, ConnectionTimeout, Consumer, ConsumerTagGenerator, ConsumerWorkPool, DeliveryInfo, Exception, Exchange, ForcedChannelCloseError, ForcedConnectionCloseError, FrameError, GetResponse, HeartbeatSender, HostListDepleted, InconsistentDataError, InternalError, MessageError, MessageProperties, MissingTLSCertificateFile, MissingTLSKeyFile, NetworkErrorWrapper, NetworkFailure, NoFinalOctetError, NotAllowedError, NotFound, PossibleAuthenticationFailureError, PreconditionFailed, ProtocolError, Queue, ReaderLoop, ResourceError, ResourceLocked, ReturnInfo, Session, ShutdownSignal, TCPConnectionFailed, TCPConnectionFailedForAllHosts, TestKit, Timestamp, Transport, UnexpectedFrame, VersionedDeliveryTag

Constant Summary collapse

PROTOCOL_VERSION =

AMQP protocol version Bunny implements

AMQ::Protocol::PROTOCOL_VERSION
SocketImpl =
Socket
Client =

backwards compatibility

Session
Timeout =
::Timeout
Timer =

Backwards compatibility

Timeout
VERSION =

Returns Version of the library.

Returns:

  • (String)

    Version of the library

"2.23.0"
ConnectionError =

backwards compatibility

TCPConnectionFailed
ServerDownError =
TCPConnectionFailed
SSLSocketImpl =
SSLSocket

Class Method Summary collapse

Class Method Details

.new(connection_string_or_opts = ENV['RABBITMQ_URL'], optz = {}) ⇒ Bunny::Session

Instantiates a new connection. The actual network connection is started with Bunny::Session#start

Parameters:

  • connection_string_or_opts (String, Hash) (defaults to: ENV['RABBITMQ_URL'])

    Connection string or a hash of connection options

  • optz (Hash) (defaults to: {})

    Extra options not related to connection

Options Hash (connection_string_or_opts):

  • :host (String) — default: "127.0.0.1"

    Hostname or IP address to connect to

  • :hosts (Array<String>) — default: ["127.0.0.1"]

    list of hostname or IP addresses to select hostname from when connecting

  • :addresses (Array<String>) — default: ["127.0.0.1:5672"]

    list of addresses to select hostname and port from when connecting

  • :port (Integer) — default: 5672

    Port RabbitMQ listens on

  • :username (String) — default: "guest"

    Username

  • :password (String) — default: "guest"

    Password

  • :vhost (String) — default: "/"

    Virtual host to use

  • :heartbeat (Integer, Symbol) — default: :server

    Heartbeat timeout to offer to the server. :server means use the value suggested by RabbitMQ. 0 means heartbeats and socket read timeouts will be disabled (not recommended).

  • :network_recovery_interval (Integer) — default: 4

    Recovery interval periodic network recovery will use. This includes initial pause after network failure.

  • :tls (Boolean) — default: false

    Should TLS/SSL be used?

  • :tls_cert (String) — default: nil

    Path to client TLS/SSL certificate file (.pem)

  • :tls_key (String) — default: nil

    Path to client TLS/SSL private key file (.pem)

  • :tls_ca_certificates (Array<String>)

    Array of paths to TLS/SSL CA files (.pem), by default detected from OpenSSL configuration

  • :verify_peer (String) — default: true

    Whether TLS peer verification should be performed

  • :tls_protocol (Symbol) — default: negotiated

    What TLS version should be used (:TLSv1, :TLSv1_1, or :TLSv1_2)

  • :channel_max (Integer) — default: 2047

    Maximum number of channels allowed on this connection, minus 1 to account for the special channel 0.

  • :continuation_timeout (Integer) — default: 15000

    Timeout for client operations that expect a response (e.g. Bunny::Queue#get), in milliseconds.

  • :connection_timeout (Integer) — default: 30

    Timeout in seconds for connecting to the server.

  • :read_timeout (Integer) — default: 30

    TCP socket read timeout in seconds. If heartbeats are disabled this will be ignored.

  • :write_timeout (Integer) — default: 30

    TCP socket write timeout in seconds.

  • :hosts_shuffle_strategy (Proc)

    a callable that reorders a list of host strings, defaults to Array#shuffle

  • :recovery_completed (Proc)

    a callable that will be called when a network recovery is performed

  • :logger (Logger)

    The logger. If missing, one is created using :log_file and :log_level.

  • :log_file (IO, String)

    The file or path to use when creating a logger. Defaults to STDOUT.

  • :logfile (IO, String)

    DEPRECATED: use :log_file instead. The file or path to use when creating a logger. Defaults to STDOUT.

  • :log_level (Integer)

    The log level to use when creating a logger. Defaults to LOGGER::WARN

  • :automatically_recover (Boolean) — default: true

    Should automatically recover from network failures?

  • :recovery_attempts (Integer) — default: nil

    Max number of recovery attempts, nil means forever

  • :reset_recovery_attempts_after_reconnection (Integer) — default: true

    Should recovery attempt counter be reset after successful reconnection? When set to false, the attempt counter will last through the entire lifetime of the connection object.

  • :recovery_attempt_started (Proc) — default: nil

    Will be called before every connection recovery attempt

  • :recovery_completed (Proc) — default: nil

    Will be called after successful connection recovery

  • :recover_from_connection_close (Boolean) — default: true

    Should this connection recover after receiving a server-sent connection.close (e.g. connection was force closed)?

  • :session_error_handler (Object) — default: Thread.current

    Object which responds to #raise that will act as a session error handler. Defaults to Thread.current, which will raise asynchronous exceptions in the thread that created the session.

Options Hash (optz):

  • :auth_mechanism (String) — default: "PLAIN"

    Authentication mechanism, PLAIN or EXTERNAL

  • :locale (String) — default: "PLAIN"

    Locale RabbitMQ should use

  • :connection_name (String) — default: nil

    Client-provided connection name, if any. Note that the value returned does not uniquely identify a connection and cannot be used as a connection identifier in HTTP API requests.

Returns:

See Also:



102
103
104
105
106
107
108
109
110
111
# File 'lib/bunny.rb', line 102

def self.new(connection_string_or_opts = ENV['RABBITMQ_URL'], optz = {})
  if connection_string_or_opts.respond_to?(:keys) && optz.empty?
    optz = connection_string_or_opts
  end

  conn = Session.new(connection_string_or_opts, optz)
  @default_connection ||= conn

  conn
end

.protocol_versionString

Returns AMQP protocol version Bunny implements.

Returns:

  • (String)

    AMQP protocol version Bunny implements



49
50
51
# File 'lib/bunny.rb', line 49

def self.protocol_version
  AMQ::Protocol::PROTOCOL_VERSION
end

.run(connection_string_or_opts = ENV['RABBITMQ_URL'], opts = {}, &block) ⇒ Object

Raises:

  • (ArgumentError)


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/bunny.rb', line 114

def self.run(connection_string_or_opts = ENV['RABBITMQ_URL'], opts = {}, &block)
  raise ArgumentError, 'Bunny#run requires a block' unless block

  if connection_string_or_opts.respond_to?(:keys) && opts.empty?
    opts = connection_string_or_opts
  end

  client = Session.new(connection_string_or_opts, opts)

  begin
    client.start
    block.call(client)
  ensure
    client.stop
  end

  # backwards compatibility
  :run_ok
end

.versionString

Returns Bunny version.

Returns:

  • (String)

    Bunny version



44
45
46
# File 'lib/bunny.rb', line 44

def self.version
  VERSION
end