Class: RabbitMQClient
- Inherits:
-
Object
- Object
- RabbitMQClient
- Includes:
- ObjectSpace
- Defined in:
- lib/rabbitmq_client.rb
Defined Under Namespace
Classes: Exchange, Queue, QueueConsumer, RabbitMQClientError
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #connect ⇒ Object
- #connected? ⇒ Boolean
- #disconnect ⇒ Object
- #exchange(name, type = 'fanout', durable = false) ⇒ Object
-
#initialize(options = {}) ⇒ RabbitMQClient
constructor
Instance Methods.
- #queue(name, durable = false) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ RabbitMQClient
Instance Methods
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/rabbitmq_client.rb', line 153 def initialize(={}) # server address @host = [:host] || '127.0.0.1' @port = [:port] || 5672 # login details @username = [:username] || 'guest' @password = [:password] || 'guest' @vhost = [:vhost] || '/' # queues and exchanges @queues = {} @exchanges = {} connect unless [:no_auto_connect] # Disconnect before the object is destroyed define_finalizer(self, lambda {|id| self.disconnect if self.connected? }) self end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
149 150 151 |
# File 'lib/rabbitmq_client.rb', line 149 def channel @channel end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
150 151 152 |
# File 'lib/rabbitmq_client.rb', line 150 def connection @connection end |
Instance Method Details
#connect ⇒ Object
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/rabbitmq_client.rb', line 173 def connect params = ConnectionParameters.new params.set_username(@username) params.set_password(@password) params.set_virtual_host(@vhost) params.set_requested_heartbeat(0) conn_factory = ConnectionFactory.new(params) @connection = conn_factory.new_connection(@host, @port) @channel = @connection.create_channel end |
#connected? ⇒ Boolean
191 192 193 |
# File 'lib/rabbitmq_client.rb', line 191 def connected? @connection != nil end |
#disconnect ⇒ Object
184 185 186 187 188 189 |
# File 'lib/rabbitmq_client.rb', line 184 def disconnect @queues.values.each { |q| q.unbind } @channel.close @connection.close @connection = nil end |