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

Support connection name #600

Merged
merged 3 commits into from Sep 11, 2020

Conversation

brerx
Copy link
Contributor

@brerx brerx commented Sep 11, 2020

related to #599.

  • adds connection_name as optional client_property
  • adds unit test

@brerx
Copy link
Contributor Author

brerx commented Sep 11, 2020

@michaelklishin This is my first approach to solve this.

Without the addition in docker-entrypoint, the CLI tool proceeded before the actual users were created, which resulted in countless Auth errors during testing. So this should enable more people to contribute here.

I am eager to hear your feedback, especially whether the unit test is in the right place. I was not sure whether to put it rather into the integration/connection_spec...

@@ -8,6 +8,7 @@ $server -detached

echo "Waiting for RabbitMQ to finish startup..."

sleep 10
Copy link
Member

Choose a reason for hiding this comment

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

It makes no sense to sleep before rabbitmqctl await_startup. That command waits for node boot to complete. User creation is synchronous, so I don't see any need to wait after we set up the permissions but at least it would make some sense there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, as an unrelated change, I'll remove this again. No problem.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we can address this separately if needed. Admittedly I do not use this image for testing as I usually test Bunny against RabbitMQ nodes built from source or GA releases running locally.

@@ -199,6 +201,7 @@ def initialize(connection_string_or_opts = ENV['RABBITMQ_URL'], optz = Hash.new)

client_props = opts[:properties] || opts[:client_properties] || {}
@client_properties = DEFAULT_CLIENT_PROPERTIES.merge(client_props)
@connection_name = @client_properties.fetch(:connection_name, nil)
Copy link
Member

Choose a reason for hiding this comment

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

Hash#fetch makes sense when you want a non-nil default. Should we use Hash#[] here?

@michaelklishin
Copy link
Member

This does not actually populate the client property by merging it into @client_properties. So this makes it easy to access connection name in the app but not set it, which I thought was the goal?

@brerx
Copy link
Contributor Author

brerx commented Sep 11, 2020

Ah now I think I know how you want to understand it: Instead of

Bunny.new(properties: { connection_name: 'name' } }

which will merge automatically to the @client_properties, you thought of something like this:

      @client_properties   = DEFAULT_CLIENT_PROPERTIES.merge(client_props).merge(connection_name: opts[:connection_name])

=> Bunny.new(connection_name: 'name')

Am I right? I like this even better.

@michaelklishin
Copy link
Member

Correct, it should be easy to set a connection name, reading it is primarily useful for tests and, perhaps, logging.

Bunny.new(properties: { connection_name: 'name' } } would still work. I'm not sure whether connection_name the option or client_properties should take precedence, your approach seems right.

@brerx
Copy link
Contributor Author

brerx commented Sep 11, 2020

Ok, I changed it to the easier usecase. What do you think?

michaelklishin added a commit that referenced this pull request Sep 11, 2020
@michaelklishin michaelklishin merged commit 2ce5ac3 into ruby-amqp:master Sep 11, 2020
@michaelklishin
Copy link
Member

I have updated the code to support connection names specified directly in client_properties. Will add a spec example next. The rest looks good to me.

@brerx
Copy link
Contributor Author

brerx commented Sep 11, 2020

Thx for merging this so fastly. Will you make a new release soon?

michaelklishin added a commit that referenced this pull request Sep 11, 2020
michaelklishin added a commit that referenced this pull request Sep 11, 2020
@michaelklishin
Copy link
Member

2.17.0 is up on rubygems.org.

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.

None yet

2 participants