Skip to content

Commit

Permalink
Merge pull request #305 from michaellennox/restore-uri-scheme-and-def…
Browse files Browse the repository at this point in the history
…ault-port-parsing

When using the uri config option: Respect amqps specification and use default protocol ports if unspecified
  • Loading branch information
michaelklishin authored Jan 16, 2018
2 parents 47632a0 + 3ad4b31 commit ddf310a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/hutch/broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,18 @@ def parse_uri

u = URI.parse(@config[:uri])

@config[:mq_tls] = u.scheme == 'amqps'
@config[:mq_host] = u.host
@config[:mq_port] = u.port
@config[:mq_port] = u.port || default_mq_port
@config[:mq_vhost] = u.path.sub(/^\//, "")
@config[:mq_username] = u.user
@config[:mq_password] = u.password
end

def default_mq_port
@config[:mq_tls] ? AMQ::Protocol::TLS_PORT : AMQ::Protocol::DEFAULT_PORT
end

def sanitized_uri
p = connection_params
scheme = p[:tls] ? "amqps" : "amqp"
Expand Down
30 changes: 30 additions & 0 deletions spec/hutch/broker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,36 @@

connection.close
end

context 'when configured with a URI' do
context 'which specifies the port' do
before { config[:uri] = 'amqp://guest:guest@127.0.0.1:5672/' }

it 'successfully connects' do
expect { broker.open_connection }.not_to raise_error
end
end

context 'which does not specify port and uses the amqp scheme' do
before { config[:uri] = 'amqp://guest:guest@127.0.0.1/' }

it 'successfully connects' do
expect { broker.open_connection }.not_to raise_error
end
end

context 'which specifies the amqps scheme' do
before { config[:uri] = 'amqps://guest:guest@127.0.0.1/' }

it 'utilises TLS' do
expect(Hutch::Adapter).to receive(:new).with(
hash_including(tls: true, port: 5671)
).and_return(instance_double('Hutch::Adapter', start: nil))

broker.open_connection
end
end
end
end

describe '#open_connection!' do
Expand Down

0 comments on commit ddf310a

Please sign in to comment.