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

Conversation

michaellennox
Copy link

@michaellennox michaellennox commented Jan 16, 2018

What does this PR do?

Restores functionality implemented in #159 and since lost to:

  • Respect amqps specification when using the URI config option (ie. utilise TLS)
  • Default to the standard protocol ports when not specified and using the URI config option (5671 for TLS, 5672 otherwise)

This means that:

amqp://guest:guest@127.0.0.1/ connects to the server on port 5672 and does not utilise TLS.
amqps://guest:guest@127.0.0.1/ connects to the server on port 5671 and does utilise TLS.

It also adds test cases for this functionality to prevent another regression.

Where should the reviewer start?

Changes are all within Hutch::Broker#parse_uri

Any background context you want to provide?

Background context can be found in the original issue ://github.com//issues/304

Any specific implementation details?

The test for covering when amqps scheme is utilised has to stub out Hutch::Adapter instead of acting like an integration test in a similar manner to the surrounding specs because it appears a default rabbitmq install does not activate TLS listeners and as such a user who was to run the test suite without changing their rabbitmq server config would get failing specs if the adapter was not stubbed.

\cc @michaelklishin

@michaellennox michaellennox force-pushed the restore-uri-scheme-and-default-port-parsing branch 2 times, most recently from 3cc2e48 to e83bdc7 Compare January 16, 2018 09:39
Copy link
Member

@michaelklishin michaelklishin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks promising but can be improved further. Thank you!

@config[:mq_vhost] = u.path.sub(/^\//, "")
@config[:mq_username] = u.user
@config[:mq_password] = u.password
end

def default_mq_port
@config[:mq_tls] ? 5671 : 5672
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please switch to AMQ::Protocol::DEFAULT_PORT and AMQ::Protocol::TLS_PORT.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @michaelklishin , ♻️

In ruby-amqp#159 functionality was added to hutch that meant that it would respect that when using `amqps://` as the URI scheme it would use TLS and also that when not specifying a port in the URI scheme it would default to the standard protocol ports (5671 for TLS connections, 5672 for non TLS connections).

This functionality appears to have been lost since and is restored by this commit it also adds a new test case to prevent another regression.
@michaellennox michaellennox force-pushed the restore-uri-scheme-and-default-port-parsing branch from e83bdc7 to 3ad4b31 Compare January 16, 2018 11:48
@michaellennox
Copy link
Author

Are failures in the JRuby build expected?

Looking at the travis output all the specs passed but travis marked the build as a failure as it believed the build timed out: https://travis-ci.org/gocardless/hutch/jobs/329386746

@michaelklishin
Copy link
Member

With JRuby you have to properly close connections or the JVM won't ever terminate because RabbitMQ Java client will have an execution service with running non-daemon threads. So it's not related.

@michaelklishin michaelklishin merged commit ddf310a into ruby-amqp:master Jan 16, 2018
michaelklishin added a commit that referenced this pull request Jan 17, 2018
 * amq-protocol is not used on JRuby
 * All connections must be closed on JRuby since Hutch/MarchHare
   do not instruct RabbitMQ Java client to use daemon threads.
   Not doing so will result in hanging test suites since the JVM
   won't terminate with live non-daemon threads.

References #302, #305.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants