Class: RubyRabbitmqJanus::Rabbit::Propertie

Inherits:
Object
  • Object
show all
Defined in:
lib/rrj/rabbit/propertie.rb

Overview

Manage properties to message sending in rabbitmq queue

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance = 1) ⇒ Propertie

Initialize a message sending to rabbitmq



15
16
17
18
19
# File 'lib/rrj/rabbit/propertie.rb', line 15

def initialize(instance = 1)
  ::Log.debug 'initalize a propertie to message'
  @correlation = SecureRandom.uuid
  @instance = instance
end

Instance Attribute Details

#correlationString (readonly)

Returns Is a string uniq generated by SecureRandom.

Returns:

  • (String)

    Is a string uniq generated by SecureRandom



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rrj/rabbit/propertie.rb', line 11

class Propertie
  attr_reader :correlation

  # Initialize a message sending to rabbitmq
  def initialize(instance = 1)
    ::Log.debug 'initalize a propertie to message'
    @correlation = SecureRandom.uuid
    @instance = instance
  end

  # Define options sending to RabbitMQ
  def options
    base.merge(routing_key: routing_key)
  end

  # Define option sending to rabbitmq for janus admin message
  def options_admin
    base.merge(routing_key: routing_key_admin)
  end

  private

  def determine_routing_key(type_request)
    cluster = Tools::Cluster.instance

    if type_request.include?('admin')
      cluster.queue_admin_to(@instance)
    else
      cluster.queue_to(@instance)
    end
  end

  def base
    { correlation_id: @correlation, content_type: 'application/json' }
  end

  def routing_key
    Tools::Cluster.instance.queue_to(@instance)
  end

  def routing_key_admin
    Tools::Cluster.instance.queue_admin_to(@instance)
  end
end

Instance Method Details

#optionsObject

Define options sending to RabbitMQ



22
23
24
# File 'lib/rrj/rabbit/propertie.rb', line 22

def options
  base.merge(routing_key: routing_key)
end

#options_adminObject

Define option sending to rabbitmq for janus admin message



27
28
29
# File 'lib/rrj/rabbit/propertie.rb', line 27

def options_admin
  base.merge(routing_key: routing_key_admin)
end