Module: GovukMessageQueueConsumer::RabbitMQConfig

Defined in:
lib/govuk_message_queue_consumer/rabbitmq_config.rb

Defined Under Namespace

Classes: ConfigurationError

Class Method Summary collapse

Class Method Details

.fetch(env, variable_name) ⇒ Object



15
16
17
# File 'lib/govuk_message_queue_consumer/rabbitmq_config.rb', line 15

def self.fetch(env, variable_name)
  env[variable_name] || raise_error(variable_name)
end

.from_environment(env) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/govuk_message_queue_consumer/rabbitmq_config.rb', line 6

def self.from_environment(env)
  {
    hosts: fetch(env, "RABBITMQ_HOSTS").split(","),
    vhost: fetch(env, "RABBITMQ_VHOST"),
    user: fetch(env, "RABBITMQ_USER"),
    pass: fetch(env, "RABBITMQ_PASSWORD"),
  }
end

.raise_error(variable_name) ⇒ Object

Raises:



19
20
21
22
23
24
25
26
27
28
# File 'lib/govuk_message_queue_consumer/rabbitmq_config.rb', line 19

def self.raise_error(variable_name)
  raise ConfigurationError, <<-ERR
    The environment variable #{variable_name} is not set. If you are in test
    mode, make sure you set the correct vars in your helpers. If you get this
    error in development, make sure you run rails or rake with `govuk_setenv`
    and puppet is up to date. RABBITMQ_HOSTS, RABBITMQ_VHOST,
    RABBITMQ_USER and RABBITMQ_PASSWORD are deprecated. Please switch to
    RABBITMQ_URL.
  ERR
end