Package Usage: go: github.com/bufbuild/httplb
Package httplb provides http.Client instances that are suitable
for use for server-to-server communications, like RPC. This adds features
on top of the standard net/http library for name/address resolution,
health checking, and load balancing. It also provides more suitable
defaults and much simpler support for HTTP/2 over plaintext.
To create a new client use the NewClient function. This function
accepts numerous options, many for configuring the behavior of the
underlying transports. It also provides options for using a custom
name resolver or a custom load balancing policy and for enabling
active health checking.
The returned client also has a notion of "closing", via its Close
method. This step will wait for outstanding requests to complete and
then close all connections and also teardown any other goroutines that
it may have started to perform name resolution and health checking.
The client cannot be used after it has been closed.
Without any options, the returned client behaves differently than
http.DefaultClient in the following key ways:
The client will re-resolve addresses in DNS every 5 minutes.
The http.DefaultClient does not re-resolve predictably.
The client will route requests in a round-robin fashion to all
addresses returned by the DNS system (both A and AAAA records).
even with HTTP/2.
This differs from the http.DefaultClient, which will use only a
single connection if it can, even if DNS resolves many addresses.
With HTTP 1.1, an http.DefaultClient will create additional
connections to handle multiple concurrent requests (since an HTTP
1.1 connection can only service one request at a time). But with
HTTP/2, it likely will *never* use additional connections: it
only creates another connection if the concurrency limit exceeds
the server's "max concurrent streams" (which the server provides
when the connection is initially established and is typically on
the order of 100).
The above behavior alone should make the httplb.Client distribute load
to backends in a much more appropriate way, especially when using HTTP/2.
But the real power of a client returned by this package is that it
can be customized with different name resolution and load balancing
policies, via the WithResolver and WithPicker options. Active health
checking can be enabled via the WithHealthChecks option.
The clients created by this function use a transport implementation
that is actually a hierarchy of three layers:
One of the options in this package, WithTransport, allows users to
implement custom transports and select them using custom URL schemes.
This could be used, for example, to enable HTTP/3 with a URL such as
"http3://...".
This package even uses this capability to provide simple use of HTTP/2
over plaintext, also called "h2c". In addition to supporting "http" and
"https" URL schemes, this package also supports "h2c" as a URL scheme.
1 version
Latest release: over 1 year ago
View more package details: https://packages.ecosyste.ms/registries/proxy.golang.org/packages/github.com/bufbuild/httplb
Dependent Repos 1
jchadwick-buf/goproxy-github-cache
Work in progress. Experiment to improve GHA Windows CI time.Size: 63.5 KB - Last synced: about 2 months ago - Pushed: over 1 year ago

longbai/connect-rpc-demo
grpc implement instead of connect-rpcSize: 21.5 KB - Last synced: about 1 year ago - Pushed: about 1 year ago


