Class: Surfliner::Mq::QueueConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/surfliner/mq/queue_config.rb

Overview

Encapsulates queue configuration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, options: {}) ⇒ QueueConfig

Returns a new instance of QueueConfig.

Parameters:

  • name (String)

    queue exchange to listen to

  • options (Hash) (defaults to: {})

    RabbitMQ queue options. (See Bunny::Channel#queue)



13
14
15
16
# File 'lib/surfliner/mq/queue_config.rb', line 13

def initialize(name:, options: {})
  @name = name
  @options = options
end

Instance Attribute Details

#nameString (readonly)

Returns The queue to listen to.

Returns:

  • (String)

    The queue to listen to



6
7
8
# File 'lib/surfliner/mq/queue_config.rb', line 6

def name
  @name
end

#optionsHash (readonly)

Returns RabbitMQ queue options. (See Bunny::Channel#queue).

Returns:

  • (Hash)

    RabbitMQ queue options. (See Bunny::Channel#queue)



9
10
11
# File 'lib/surfliner/mq/queue_config.rb', line 9

def options
  @options
end

Class Method Details

.from_env(**options) ⇒ QueueConfig

Returns a default (environment-variable-based) configuration with the specified options.

Variable Sample value Description
RABBITMQ_QUEUE surfliner.metadata RabbitMQ queue name

Parameters:

  • options (Hash)

    RabbitMQ queue options. (See Bunny::Channel#queue)

Returns:



52
53
54
55
56
57
# File 'lib/surfliner/mq/queue_config.rb', line 52

def from_env(**options)
  QueueConfig.new(
    name: ENV.fetch("RABBITMQ_QUEUE"),
    options:
  )
end

Instance Method Details

#==(other) ⇒ Boolean

Whether other represents the same configuration as this object. Note that if name or options are modified, equality becomes unstable.

Parameters:

  • other (Object, nil)

    the object to compare

Returns:

  • (Boolean)

    true if other represents the same configuration as this object, false otherwise



30
31
32
33
# File 'lib/surfliner/mq/queue_config.rb', line 30

def ==(other)
  return unless other.class == self.class
  other.name == name && other.options == options
end

#eql?(other) ⇒ Boolean

Whether other represents the same configuration as this object. Note that if name or options are modified, equality becomes unstable.

Parameters:

  • other (Object, nil)

    the object to compare

Returns:

  • (Boolean)

    true if other represents the same configuration as this object, false otherwise



22
23
24
# File 'lib/surfliner/mq/queue_config.rb', line 22

def eql?(other)
  self == other
end

#hashInteger

The hash value of this object. Equal configurations will have equal hash values. Note that if name or options are modified, the hash value becomes unstable.

Returns:

  • (Integer)

    a hash value suitable for using equal configs as hash keys



38
39
40
# File 'lib/surfliner/mq/queue_config.rb', line 38

def hash
  [name, options].hash
end