Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using the uri config option: Respect amqps specification and use default protocol ports if unspecified #305

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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