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

[RabbitMQ] Reusing healthy connection #352

Merged
merged 10 commits into from
Jan 20, 2020
Merged

[RabbitMQ] Reusing healthy connection #352

merged 10 commits into from
Jan 20, 2020

Conversation

rwkarg
Copy link
Contributor

@rwkarg rwkarg commented Dec 3, 2019

This ensures that a connection that remains open will be reused within a RabbitMQHealthCheck instance

The `ConnectionFactory` doesn't handle a null SslOption field for amqp connections. It must be a created instance with Enabled=false

The constructor for a new `ConnectionFactory` will create a new SslOption already so only overwriting that default if something was passed in to the constructor.
Removing Lazy that was only created to return an already created instance
@rwkarg
Copy link
Contributor Author

rwkarg commented Dec 3, 2019

Not sure how the tests were passing before the change either. It has always tried to create a new Uri(rabbitMqConnectionString) and I didn't change that.

@rwkarg
Copy link
Contributor Author

rwkarg commented Dec 3, 2019

@unaizorrilla

@rwkarg
Copy link
Contributor Author

rwkarg commented Dec 3, 2019

ConnectionFactory used to be Lazy so it was never getting to the attempt to parse the Uri. Updating tests.

@rwkarg
Copy link
Contributor Author

rwkarg commented Dec 5, 2019

@unaizorrilla This PR already addressed the null sslOption handling. Resolving conflicts with 6adb624

@rwkarg
Copy link
Contributor Author

rwkarg commented Dec 9, 2019

Adding unit tests on the actual health check since there are now many entry points that need to be verified as working.

@unaizorrilla Any guidance on a Mocking framework to use (Moq?)?

I don't see any other tests that mock anything out right now.

@rwkarg
Copy link
Contributor Author

rwkarg commented Dec 16, 2019

@unaizorrilla - Is there someone else I should ping if you're not able to get to reviewing this?

@unaizorrilla
Copy link
Collaborator

Hi @rwkarg

I try to review this a after xmas holidays! :-)

@rwkarg
Copy link
Contributor Author

rwkarg commented Dec 31, 2019

👍 enjoy the rest of your holiday!

src/HealthChecks.RabbitMQ/RabbitMQHealthCheck.cs Outdated Show resolved Hide resolved
src/HealthChecks.RabbitMQ/RabbitMQHealthCheck.cs Outdated Show resolved Hide resolved
@@ -28,7 +28,7 @@ public static IHealthChecksBuilder AddRabbitMQ(this IHealthChecksBuilder builder
{
return builder.Add(new HealthCheckRegistration(
name ?? NAME,
sp => new RabbitMQHealthCheck(rabbitMQConnectionString, sslOption),
new RabbitMQHealthCheck(rabbitMQConnectionString, sslOption),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why?
I

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When passing in a Func to HealthCheckRegistration, that Func gets called every time that a health check is evaluated.
This resulted in a new RabbitMQHealthCheck instance being created for every health check evaluation. This further lead to a new ConnectionFactory and Connection being created for each health check evaluation which eliminated reuse (a RabbitMQHealthCheck will reuse an already provided/created ConnectionFactory/Connection but if a new RabbitMQHealthCheck is created each time then that reuse can't happen since it's a fresh instance each time).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @rwkarg

True, I try to merge asap!

Copy link
Contributor Author

@rwkarg rwkarg left a comment

Choose a reason for hiding this comment

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

Updates made based on feedback and clarification provided

@@ -28,7 +28,7 @@ public static IHealthChecksBuilder AddRabbitMQ(this IHealthChecksBuilder builder
{
return builder.Add(new HealthCheckRegistration(
name ?? NAME,
sp => new RabbitMQHealthCheck(rabbitMQConnectionString, sslOption),
new RabbitMQHealthCheck(rabbitMQConnectionString, sslOption),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When passing in a Func to HealthCheckRegistration, that Func gets called every time that a health check is evaluated.
This resulted in a new RabbitMQHealthCheck instance being created for every health check evaluation. This further lead to a new ConnectionFactory and Connection being created for each health check evaluation which eliminated reuse (a RabbitMQHealthCheck will reuse an already provided/created ConnectionFactory/Connection but if a new RabbitMQHealthCheck is created each time then that reuse can't happen since it's a fresh instance each time).

@unaizorrilla unaizorrilla merged commit 388d7ac into Xabaril:master Jan 20, 2020
@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.

3 participants