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
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/rabbitmq_client.rb', line 140 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.
136 137 138 |
# File 'lib/rabbitmq_client.rb', line 136 def channel @channel end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
137 138 139 |
# File 'lib/rabbitmq_client.rb', line 137 def connection @connection end |
Instance Method Details
#connect ⇒ Object
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/rabbitmq_client.rb', line 160 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
177 178 179 |
# File 'lib/rabbitmq_client.rb', line 177 def connected? @connection != nil end |
#disconnect ⇒ Object
171 172 173 174 175 |
# File 'lib/rabbitmq_client.rb', line 171 def disconnect @channel.close @connection.close @connection = nil end |