-
Notifications
You must be signed in to change notification settings - Fork 83
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
MINOR FIX: PENDING New Version of RESTFulSense with HttpFactory #20
Comments
http://byterot.blogspot.com/2016/07/singleton-httpclient-dns.html Use the HttpClientFactory. The library should inject the HttpClientFactory or request it as a required service, and then create a configured client that can be reused for the OpenAI endpoint. Thankyou @jodendaal for pointing this out. |
@jodendaal please create an issue on the cc: @cjdutoit |
@hassanhabib I've just created a PR #77 demonstrating how to use IHttpClientFactory from Microsoft.Extensions.Http. We can use that library to register both our http client and IRESTFulClientFactory in DI. I think this way we can have a cleaner code in the OpenAIBroker. |
@rafsanulhasan every broker should contain it's own dependencies. Brokers should only receive configurations and initialize it's own external libraries. Refer to this portion here in The Standard: We should have bits and pieces of Broker's requirements spread across the app. |
@hassanhabib I've just created another PR #84 which allows you to put own dependencies for different brokers. This time tried to maintain the standard. |
If creating a HttpClient manually, i.e new HttpClient() that is either disposed frequently or is long running,it is recommended to create your own [HttpMessageHandler] and handle lifetimes etc to avoid socket exhaustion and DNS update failures. I would recommend just using the IHttpClientFactory to create new http instances which handles all of this really well.
I have dealt with this issue quite a few times in production environments with long running high through put scenarios. It's not an obvious issue, but eventually rears its ugly head.
Further Reading
https://learn.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests
https://www.aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/
The text was updated successfully, but these errors were encountered: