diff --git a/lib/hutch/broker.rb b/lib/hutch/broker.rb index db0f050d..eebaaa4d 100644 --- a/lib/hutch/broker.rb +++ b/lib/hutch/broker.rb @@ -11,6 +11,24 @@ class Broker attr_accessor :connection, :channel, :exchange, :api_client + + DEFAULT_AMQP_PORT = + case RUBY_ENGINE + when "jruby" then + com.rabbitmq.client.ConnectionFactory::DEFAULT_AMQP_PORT + when "ruby" then + AMQ::Protocol::DEFAULT_PORT + end + + DEFAULT_AMQPS_PORT = + case RUBY_ENGINE + when "jruby" then + com.rabbitmq.client.ConnectionFactory::DEFAULT_AMQP_OVER_SSL_PORT + when "ruby" then + AMQ::Protocol::TLS_PORT + end + + # @param config [nil,Hash] Configuration override def initialize(config = nil) @config = config || Hutch::Config @@ -301,7 +319,7 @@ def parse_uri end def default_mq_port - @config[:mq_tls] ? AMQ::Protocol::TLS_PORT : AMQ::Protocol::DEFAULT_PORT + @config[:mq_tls] ? DEFAULT_AMQPS_PORT : DEFAULT_AMQP_PORT end def sanitized_uri diff --git a/spec/hutch/broker_spec.rb b/spec/hutch/broker_spec.rb index 7f293ca3..22177659 100644 --- a/spec/hutch/broker_spec.rb +++ b/spec/hutch/broker_spec.rb @@ -98,7 +98,9 @@ before { config[:uri] = 'amqp://guest:guest@127.0.0.1:5672/' } it 'successfully connects' do - expect { broker.open_connection }.not_to raise_error + c = broker.open_connection + expect(c).to be_open + c.close end end @@ -106,7 +108,9 @@ before { config[:uri] = 'amqp://guest:guest@127.0.0.1/' } it 'successfully connects' do - expect { broker.open_connection }.not_to raise_error + c = broker.open_connection + expect(c).to be_open + c.close end end