package hyperbahn
import "github.com/uber/tchannel-go/hyperbahn"
Index ¶
- type AdRequest
- type AdResponse
- type Client
- func NewClient(ch *tchannel.Channel, config Configuration, opts *ClientOptions) (*Client, error)
- func (c *Client) Advertise(otherServices ...tchannel.Registrar) error
- func (c *Client) Close()
- func (c *Client) Discover(serviceName string) ([]string, error)
- func (c *Client) IsClosed() bool
- type ClientOptions
- type Configuration
- type ErrAdvertiseFailed
- type Event
- type FailStrategy
- type Handler
Types ¶
type AdRequest ¶
type AdRequest struct {
Services []service `json:"services"`
}
AdRequest is the Ad request sent to Hyperbahn.
type AdResponse ¶
type AdResponse struct { ConnectionCount int `json:"connectionCount"` }
AdResponse is the Ad response from Hyperbahn.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client manages Hyperbahn connections and registrations.
func NewClient ¶
func NewClient(ch *tchannel.Channel, config Configuration, opts *ClientOptions) (*Client, error)
NewClient creates a new Hyperbahn client using the given channel. config is the environment-specific configuration for Hyperbahn such as the list of initial nodes. opts are optional, and are used to customize the client.
func (*Client) Advertise ¶
Advertise advertises the service with Hyperbahn, and returns any errors on initial advertisement. Advertise can register multiple services hosted on the same endpoint. If the advertisement succeeds, a goroutine is started to re-advertise periodically.
func (*Client) Close ¶
func (c *Client) Close()
Close closes the Hyperbahn client, which stops any background re-advertisements.
func (*Client) Discover ¶
Discover queries Hyperbahn for a list of peers that are currently advertised with the specified service name.
func (*Client) IsClosed ¶
IsClosed returns whether this Client is closed.
type ClientOptions ¶
type ClientOptions struct { // Timeout defaults to 3 seconds if it is not set. Timeout time.Duration // TimeoutPerAttempt defaults to 1 second if it is not set. TimeoutPerAttempt time.Duration Handler Handler FailStrategy FailStrategy // The following are variables for stubbing in unit tests. // They are not part of the stable API and may change. TimeSleep func(d time.Duration) }
ClientOptions are used to configure this Hyperbahn client.
type Configuration ¶
type Configuration struct { // InitialNodes is the list of known Hyperbahn nodes to add initially. InitialNodes []string // InitialNodesFile is a JSON file that contains the list of known Hyperbahn nodes. // If this option is set, it overrides InitialNodes. InitialNodesFile string }
Configuration is the initial configuration
type ErrAdvertiseFailed ¶
type ErrAdvertiseFailed struct { // WillRetry is set to true if advertise will be retried. WillRetry bool // Cause is the underlying error returned from the advertise call. Cause error }
ErrAdvertiseFailed is triggered when advertise fails.
func (ErrAdvertiseFailed) Error ¶
func (e ErrAdvertiseFailed) Error() string
type Event ¶
type Event int
Event describes different events that Client can trigger.
const ( // UnknownEvent should never be used. UnknownEvent Event = iota // SendAdvertise is triggered when the Hyperbahn client tries to advertise. SendAdvertise // Advertised is triggered when the initial advertisement for a service is successful. Advertised // Readvertised is triggered on periodic advertisements. Readvertised )
func (Event) String ¶
type FailStrategy ¶
type FailStrategy int
FailStrategy is the strategy to use when registration fails maxRegistrationFailures times consecutively in the background. This is not used if the initial registration fails.
const ( // FailStrategyFatal will call Fatalf on the channel's logger after triggering handler.OnError. // This is the default strategy. FailStrategyFatal FailStrategy = iota // FailStrategyIgnore will only call handler.OnError, even after many // errors, and will continue to retry forever. FailStrategyIgnore )
func (*FailStrategy) UnmarshalText ¶
func (f *FailStrategy) UnmarshalText(text []byte) error
UnmarshalText implements encoding/text.Unmarshaler. This allows FailStrategy to be specified as a string in many file formats (e.g. JSON, YAML, TOML).
type Handler ¶
type Handler interface { // On is called when events are triggered. On(event Event) // OnError is called when an error is detected. OnError(err error) }
Handler is the interface for handling Hyperbahn events and errors.
Source Files ¶
advertise.go call.go client.go configuration.go discover.go event_string.go events.go utils.go
Directories ¶
Path | Synopsis |
---|---|
hyperbahn/gen-go | |
hyperbahn/gen-go/hyperbahn | Package hyperbahn is generated code used to make or handle TChannel calls using Thrift. |
- Version
- v1.34.6 (latest)
- Published
- Jan 8, 2025
- Platform
- windows/amd64
- Imports
- 12 packages
- Last checked
- 1 week ago –
Tools for package owners.