Documentation ¶
Overview ¶
Package forward provides a mechanism to forward TChannel requests.
Index ¶
- func HasForwardedHeader(ctx thrift.Context) bool
- func SetForwardedHeader(ctx thrift.Context) thrift.Context
- type FailedEvent
- type Forwarder
- type InflightCountOperation
- type InflightRequestsChangedEvent
- type InflightRequestsMiscountEvent
- type MaxRetriesEvent
- type Options
- type RequestForwardedEvent
- type RerouteEvent
- type RetryAbortEvent
- type RetryAttemptEvent
- type RetrySuccessEvent
- type Sender
- type SuccessEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasForwardedHeader ¶
HasForwardedHeader takes the headers that came in via TChannel and looks for the precense of a specific ringpop header to see if ringpop already forwarded the message. When a message has already been forwarded by ringpop the forwarding logic should not be used to prevent unbound forwarding.
func SetForwardedHeader ¶
SetForwardedHeader adds a header to the current thrift context indicating that the call has been forwarded by another node in the ringpop ring. This header is used when a remote call is received to determine if forwarding checks needs to be applied. By not forwarding already forwarded calls we prevent unbound forwarding in the ring in case of memebership disagreement.
Types ¶
type FailedEvent ¶
type FailedEvent struct{}
A FailedEvent is emitted when the forwarded request responded with an error
type Forwarder ¶
type Forwarder struct {
// contains filtered or unexported fields
}
A Forwarder is used to forward requests to their destinations
func NewForwarder ¶
func NewForwarder(s Sender, ch shared.SubChannel) *Forwarder
NewForwarder returns a new forwarder
func (*Forwarder) ForwardRequest ¶
func (f *Forwarder) ForwardRequest(request []byte, destination, service, endpoint string, keys []string, format tchannel.Format, opts *Options) ([]byte, error)
ForwardRequest forwards a request to the given service and endpoint returns the response. Keys are used by the sender to lookup the destination on retry. If you have multiple keys and their destinations diverge on a retry then the call is aborted.
func (*Forwarder) RegisterListener ¶
func (f *Forwarder) RegisterListener(l events.EventListener)
RegisterListener adds a listener to the forwarder. The listener's HandleEvent will be called for every emit on Forwarder. The HandleEvent method must be thread safe
type InflightCountOperation ¶
type InflightCountOperation string
InflightCountOperation indicates the operation being performed on the inflight counter
const ( // InflightIncrement indicates that the inflight number was being incremented InflightIncrement InflightCountOperation = "increment" // InflightDecrement indicates that the inflight number was being decremented InflightDecrement InflightCountOperation = "decrement" )
type InflightRequestsChangedEvent ¶
type InflightRequestsChangedEvent struct {
Inflight int64
}
A InflightRequestsChangedEvent is emitted everytime the number of inflight requests change
type InflightRequestsMiscountEvent ¶
type InflightRequestsMiscountEvent struct {
Operation InflightCountOperation
}
A InflightRequestsMiscountEvent is emitted when a miscount happend for the inflight requests
type MaxRetriesEvent ¶
type MaxRetriesEvent struct {
MaxRetries int
}
A MaxRetriesEvent is emitted when the sender failed to complete the request after the maximum specified amount of retries
type Options ¶
type Options struct { MaxRetries int RerouteRetries bool RetrySchedule []time.Duration Timeout time.Duration }
Options for the creation of a forwarder
type RequestForwardedEvent ¶
type RequestForwardedEvent struct{}
A RequestForwardedEvent is emitted for every forwarded request
type RerouteEvent ¶
A RerouteEvent is emitted when a forwarded request is being rerouted to a new destination
type RetryAbortEvent ¶
type RetryAbortEvent struct {
Reason string
}
A RetryAbortEvent is emitted when a retry has been aborted. The reason for abortion is embedded
type RetryAttemptEvent ¶
type RetryAttemptEvent struct{}
A RetryAttemptEvent is emitted when a retry is initiated during forwarding
type RetrySuccessEvent ¶
type RetrySuccessEvent struct {
NumRetries int
}
A RetrySuccessEvent is emitted after a retry resulted in a successful forwarded request
type Sender ¶
type Sender interface { // WhoAmI should return the address of the local sender WhoAmI() (string, error) // Lookup should return the server the request belongs to Lookup(string) (string, error) }
A Sender is used to route the request to the proper destination, the server returned by Lookup(key)
type SuccessEvent ¶
type SuccessEvent struct{}
A SuccessEvent is emitted when the forwarded request responded without an error