Class: Packageiq::Transport::Rabbitmq

Inherits:
Object
  • Object
show all
Defined in:
lib/packageiq/transport/rabbitmq.rb

Overview

rabbitmq transport

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Rabbitmq

Returns a new instance of Rabbitmq.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/packageiq/transport/rabbitmq.rb', line 12

def initialize(args = {})
  @host                   = args[:host] || '127.0.0.1'
  @port                   = args[:port] || 5672
  @tls                    = args[:tls] || false
  @tls_cert               = args[:tls_cert] || ''
  @tls_key                = args[:tls_key] || ''
  @tls_ca_certificates    = args[:tls_ca_certificates] || []
  @vhost                  = args[:vhost] || '/'
  @user                   = args[:user] || 'guest'
  @pass                   = args[:pass] || 'guest'
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



41
42
43
# File 'lib/packageiq/transport/rabbitmq.rb', line 41

def channel
  @channel
end

#connObject (readonly)

Returns the value of attribute conn.



29
30
31
# File 'lib/packageiq/transport/rabbitmq.rb', line 29

def conn
  @conn
end

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/packageiq/transport/rabbitmq.rb', line 8

def host
  @host
end

#passObject

Returns the value of attribute pass.



8
9
10
# File 'lib/packageiq/transport/rabbitmq.rb', line 8

def pass
  @pass
end

#portObject

Returns the value of attribute port.



8
9
10
# File 'lib/packageiq/transport/rabbitmq.rb', line 8

def port
  @port
end

#queueObject (readonly)

Returns the value of attribute queue.



53
54
55
# File 'lib/packageiq/transport/rabbitmq.rb', line 53

def queue
  @queue
end

#tlsObject

Returns the value of attribute tls.



8
9
10
# File 'lib/packageiq/transport/rabbitmq.rb', line 8

def tls
  @tls
end

#tls_ca_certificatesObject

Returns the value of attribute tls_ca_certificates.



8
9
10
# File 'lib/packageiq/transport/rabbitmq.rb', line 8

def tls_ca_certificates
  @tls_ca_certificates
end

#tls_certObject

Returns the value of attribute tls_cert.



8
9
10
# File 'lib/packageiq/transport/rabbitmq.rb', line 8

def tls_cert
  @tls_cert
end

#tls_keyObject

Returns the value of attribute tls_key.



8
9
10
# File 'lib/packageiq/transport/rabbitmq.rb', line 8

def tls_key
  @tls_key
end

#userObject

Returns the value of attribute user.



8
9
10
# File 'lib/packageiq/transport/rabbitmq.rb', line 8

def user
  @user
end

#vhostObject

Returns the value of attribute vhost.



8
9
10
# File 'lib/packageiq/transport/rabbitmq.rb', line 8

def vhost
  @vhost
end

Class Method Details

.serialize(message) ⇒ Object

serialize message



25
26
27
# File 'lib/packageiq/transport/rabbitmq.rb', line 25

def self.serialize(message)
  message.to_json
end

Instance Method Details

#close_channelObject

close rabbitmq channel



49
50
51
# File 'lib/packageiq/transport/rabbitmq.rb', line 49

def close_channel
  @channel.close_channel
end

#create_channelObject

create rabbitmq channel



44
45
46
# File 'lib/packageiq/transport/rabbitmq.rb', line 44

def create_channel
  @channel = conn.create_channel
end

#create_queue(name, opts = {}) ⇒ Object

create rabbitmq queue



56
57
58
59
60
61
62
63
64
# File 'lib/packageiq/transport/rabbitmq.rb', line 56

def create_queue(name, opts = {})
  durable     = opts[:durable] || false
  auto_delete = opts[:auto_delete] || false
  exclusive   = opts[:exclusive] || false
  @queue      = channel.queue(name,
                              durable: durable,
                              auto_delete: auto_delete,
                              exclusive: exclusive)
end

#queue_exists?(name) ⇒ Boolean

check if queue exists returns boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/packageiq/transport/rabbitmq.rb', line 68

def queue_exists?(name)
  conn.queue_exists?(name)
end

#startObject

initialize bunny instance and start connection



32
33
34
35
36
37
38
39
# File 'lib/packageiq/transport/rabbitmq.rb', line 32

def start
  @conn = Bunny.new(host: host, port: port,
                    tls: tls, tls_cert: tls_cert,
                    tls_key: tls_key,
                    tls_ca_certificates: tls_ca_certificates,
                    vhost: vhost, user: user, pass: pass)
  @conn.start
end