Class: EventQ::RabbitMq::QueueClient

Inherits:
Object
  • Object
show all
Defined in:
lib/eventq_rabbitmq/rabbitmq_queue_client.rb

Constant Summary collapse

GUEST =
'guest'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ QueueClient

Returns a new instance of QueueClient.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/eventq_rabbitmq/rabbitmq_queue_client.rb', line 7

def initialize(options = {})

  if options[:endpoint] == nil
    raise ':endpoint must be specified.'.freeze
  end

  @endpoint = options[:endpoint]

  @port = Integer(options[:port] || 5672)

  @user = options[:user] || GUEST

  @password = options[:password] || GUEST

  @ssl = options[:ssl] == true || false

end

Instance Method Details

#connection_optionsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/eventq_rabbitmq/rabbitmq_queue_client.rb', line 25

def connection_options
  {
      :host => @endpoint,
      :port => @port,
      :user => @user,
      :pass => @password,
      :ssl => @ssl,
      :read_timeout => 4,
      :heartbeat => 8,
      :continuation_timeout => 5000,
      :automatically_recover => true,
      :network_recovery_interval => 1,
      :recover_from_connection_close => true
  }
end

#get_connectionObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/eventq_rabbitmq/rabbitmq_queue_client.rb', line 41

def get_connection
  if RUBY_PLATFORM =~ /java/
    conn = MarchHare.connect(connection_options)
  else
    conn = Bunny.new(connection_options)
  end

  conn.start
  return conn
end