Ahoyhoy’s Objects Hierarchy¶
Client Builders¶
LBClientBuilder
and SessionClientBuilder
are builders for the Client
instance. Client
is an object which makes HTTP calls using the load balancer and circuit breaker.
SessionClientBuilder¶
In the simple case, load balancing isn’t used. When SessionClientBuilder().add_session(my_session)...
is used, it returns an Endpoint
object which contains the session (my_session) passed to it. All HTTP calls will then be delegated to that session, including optional callbacks and retries.
SessionClientBuilder().add_session(my_session).build()
-> SimpleClient(session=my_session)
-> SimpleHttpEndpoint(session=my_session)
-> Endpoint(session=my_session)
-> Session
Custom HTTP Retry objects, and custom HTTP headers can also be provided to the session. For complex cases it is recommended to create a custom Session with any needed parameters (such as headers, adapters etc.).
TODO: for now there’s no way to provide custom callbacks to the Endpoint
An Endpoint
is described below.
LBClientBuilder¶
LBClientBuilder().add_lb(my_lb)...
on the otherhand uses load balancing, and still delegates HTTP calls to the Session. With each call, the LB resolves a new Host and Endpoint
, and the Endpoint is given the original Session. Actions such as client.headers.update(...) are impossible (the Session was created upfront) in this case and will throw an AttributeError. Only HTTP calls are allowed, but no other Session modifications are possible.
LBClientBuilder().add_lb(my_lb).build()
-> Client(lb=my_lb)
Client.get('/')
-> client._lb.resolve() resolves Host
-> Endpoint(host=Host)
-> Endpoint._session=ServiceDiscoveryHttpClient(Host)
-> SessionProxy
-> Session
ServiceDiscoveryHttpClient
uses Host.address and Host.port to calculate the full URL.
SessionProxy
allows the use of callbacks with Requests HTTP calls.
Endpoint¶
Endpoint
inherits from Circuit
. It delegates HTTP calls to the Session, while maintaining circuit breaking state (open or closed), which allows or prevents further HTTP calls from being made.
TODO: add separate thread to update Endpoint’s state.