Class: CFRuntime::AMQPClient
- Inherits:
-
Object
- Object
- CFRuntime::AMQPClient
- Defined in:
- lib/cf-runtime/amqp.rb
Class Method Summary collapse
-
.create(other_options = {}, &block) ⇒ Object
Creates and returns an
AMQP
connection to a single rabbitmq service. -
.create_from_svc(service_name, other_options = {}, &block) ⇒ Object
Creates and returns an
AMQP
connection to a rabbitmq service with the specified name. -
.options_for_svc(service_name, options = {}) ⇒ Object
Merges provided options with connection options for specified rabbitmq service.
Class Method Details
.create(other_options = {}, &block) ⇒ Object
Creates and returns an AMQP
connection to a single rabbitmq service. Passes optional other_options and block arguments to AMQP.connect
. Raises ArgumentError
If zero or multiple rabbitmq services are found.
9 10 11 12 13 14 15 16 17 |
# File 'lib/cf-runtime/amqp.rb', line 9 def self.create( = {}, &block) service_names = CloudApp.service_names_of_type('rabbitmq') if service_names.length != 1 raise ArgumentError.new("Expected 1 service of rabbitmq type, " + "but found #{service_names.length}. " + "Consider using create_from_svc(service_name) instead.") end create_from_svc(service_names[0],,&block) end |
.create_from_svc(service_name, other_options = {}, &block) ⇒ Object
Creates and returns an AMQP
connection to a rabbitmq service with the specified name. Passes optional other_options and block arguments to AMQP.connect
. Raises ArgumentError
If specified rabbitmq service is not found.
23 24 25 |
# File 'lib/cf-runtime/amqp.rb', line 23 def self.create_from_svc(service_name, = {}, &block) AMQP.connect((service_name), , &block) end |
.options_for_svc(service_name, options = {}) ⇒ Object
Merges provided options with connection options for specified rabbitmq service. Returns merged Hash containing (:user, :pass, :vhost, :host, :port). Raises ArgumentError
If specified rabbitmq service is not found.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cf-runtime/amqp.rb', line 30 def self.(service_name,={}) service_props = CFRuntime::CloudApp.service_props(service_name) if service_props.nil? raise ArgumentError.new("Service with name #{service_name} not found") end = [:host] = service_props[:host] [:port] = service_props[:port] [:user] = service_props[:username] [:pass] = service_props[:password] [:vhost] = service_props[:vhost] end |