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

Add ability to re-use single RabbitMQ Connection #307

Merged
merged 1 commit into from
Oct 30, 2019

Conversation

jnovick
Copy link
Contributor

@jnovick jnovick commented Oct 20, 2019

* Addresses Issue-304
* Add many configuration options that support ability to re-use a single
connection with multiple multiplexed channels.
* Add documentation around this health check to help others follow
RabbitMQ best practices
/// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
/// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param>
/// <returns>The <see cref="IHealthChecksBuilder"/>.</returns></param>
public static IHealthChecksBuilder AddRabbitMQ(this IHealthChecksBuilder builder, string name = default,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One problem here is that there is ambiguity between the existing method's signature and this one if you are only specifying a single string. I can either rename this method or consolidate into a single method where it has different behavior depending on what fields are provided to prevent this ambiguity.

Copy link

Choose a reason for hiding this comment

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

We could resolve the ambiguity by re-ordering the parameters here, but that feels a little cheaty:

public static IHealthChecksBuilder AddRabbitMQ(this IHealthChecksBuilder builder, HealthStatus? failureStatus = default, string name = default, 

I think with that ordering a call like AddRabbitMQ("amqps://broker") would resolve to the overload on L27, and if we wanted to call this overload we'd need something like AddRabbitMQ(name: "broker")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thought I had today was to add a bool indicating whether to give priority to IConnectionFactory instead of IConnection. If I make it optional. I introduce a possibly useful feature and I maintain backwards compatibility.

Copy link

Choose a reason for hiding this comment

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

that'd do it; what would that parameter be called? preferIConnectionFactoryFromServices ?

the code might get a little messy to make this work as a priority; how about making it a little narrower, something like: bool useIConnectionFactoryFromServices=false. If it's true, we only look for an IConnectionFactory, if it's false, we only look for an IConnection?

{
return new RabbitMQHealthCheck(connection);
}
else if(connectionFactory != null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

whitespace

}
```

### Without Conveniece Extension Method
Copy link
Collaborator

Choose a reason for hiding this comment

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

Convenience

AutomaticRecoveryEnabled = true
};

var connection = factory.CreateConnection();
Copy link

@ryepup ryepup Oct 21, 2019

Choose a reason for hiding this comment

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

I know this is only some sample code, but people frequently copy/paste these things and assume the code is fit for production. In this case, I don't think we want to be creating a real connection in ConfigureServices. If our amqpuri doesn't work, we want our health check to fail, and as written I think the app will fail to start.

I think we can keep this connection lazy without too much hassle using another AddSingleton overload:

.AddSingleton<IConnection>(_ => factory.CreateConnection())

@unaizorrilla
Copy link
Collaborator

Hi @jnovick

I will try to review this PR today afternoon!

@unaizorrilla unaizorrilla merged commit 12846a7 into Xabaril:master Oct 30, 2019
@unaizorrilla
Copy link
Collaborator

Hi @jnovick
Merged on master, many thanks for improve a lot this health check ( top downloaded )! I add some missing tests for cover different registration options and solve a minor issue.

After CI build I will create a new tag and when the release build finish a new package will be created with version (3.0.1)

P.S: I change also version for us 3.0 is the .NET Core Version, and next is our changes, is not semver!

@unaizorrilla
Copy link
Collaborator

Release build finished, 3.0.1 package for Rabbitmq is on Nuget

@sungam3r sungam3r mentioned this pull request Jul 30, 2023
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.

4 participants