Module: Messagebus::Validations

Included in:
ClusterMap, Connection
Defined in:
lib/messagebus/validations.rb

Overview

:nodoc:all

Instance Method Summary collapse

Instance Method Details

#valid_host?(string) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/messagebus/validations.rb', line 34

def valid_host?(string)
  Messagebus::SERVER_REGEX.match(string)
end

#validate_connection_config(host_params, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/messagebus/validations.rb', line 46

def validate_connection_config(host_params, options = {})
  if options[:ack_type] &&
    options[:ack_type] != Messagebus::ACK_TYPE_AUTO_CLIENT &&
    options[:ack_type] != Messagebus::ACK_TYPE_CLIENT
    raise InvalidAcknowledgementType.new(options[:ack_type])
  end

  if host_params.nil?
    raise InvalidHost.new(host_params)
  end

  if host_params.is_a?(Array)
    host_params.each do |string|
      unless valid_host?(string)
        raise InvalidHost.new("host should be defined as <host>:<port>, received: #{host_params}")
      end
    end
  else
    raise InvalidHost.new("host should be defined as <host>:<port>, received #{host_params}")
  end
end

#validate_destination_config(name, is_consumer = false, options = {}) ⇒ Object

Raises:



38
39
40
41
42
43
44
# File 'lib/messagebus/validations.rb', line 38

def validate_destination_config(name, is_consumer = false, options = {})
  raise InvalidDestination.new("destination name is nil") unless name

  if is_consumer && name.match(/^jms.topic/) && options[:subscription_id].nil?
    raise InvalidDestination.new("destination type TOPIC requires a subscription_id")
  end
end