Documentation ¶
Overview ¶
Package grpc implements the grpc transport.
This package is experimental and should not be used in production.
Index ¶
- Constants
- func TransportSpec(opts ...Option) yarpcconfig.TransportSpec
- type ContextWrapper
- func (c *ContextWrapper) WithCaller(caller string) *ContextWrapper
- func (c *ContextWrapper) WithEncoding(encoding string) *ContextWrapper
- func (c *ContextWrapper) WithRoutingDelegate(routingDelegate string) *ContextWrapper
- func (c *ContextWrapper) WithRoutingKey(routingKey string) *ContextWrapper
- func (c *ContextWrapper) WithService(service string) *ContextWrapper
- func (c *ContextWrapper) WithShardKey(shardKey string) *ContextWrapper
- func (c *ContextWrapper) Wrap(ctx context.Context) context.Context
- type Inbound
- type InboundConfig
- type InboundOption
- type Option
- type Outbound
- type OutboundConfig
- type OutboundOption
- type Transport
- func (t *Transport) IsRunning() bool
- func (t *Transport) NewInbound(listener net.Listener, options ...InboundOption) *Inbound
- func (t *Transport) NewOutbound(peerChooser peer.Chooser, options ...OutboundOption) *Outbound
- func (t *Transport) NewSingleOutbound(address string, options ...OutboundOption) *Outbound
- func (t *Transport) ReleasePeer(peerIdentifier peer.Identifier, peerSubscriber peer.Subscriber) error
- func (t *Transport) RetainPeer(peerIdentifier peer.Identifier, peerSubscriber peer.Subscriber) (peer.Peer, error)
- func (t *Transport) Start() error
- func (t *Transport) Stop() error
- type TransportConfig
- type TransportOption
- func BackoffStrategy(backoffStrategy backoff.Strategy) TransportOption
- func ClientMaxRecvMsgSize(clientMaxRecvMsgSize int) TransportOption
- func ClientMaxSendMsgSize(clientMaxSendMsgSize int) TransportOption
- func ServerMaxRecvMsgSize(serverMaxRecvMsgSize int) TransportOption
- func ServerMaxSendMsgSize(serverMaxSendMsgSize int) TransportOption
- func Tracer(tracer opentracing.Tracer) TransportOption
Constants ¶
const ( // CallerHeader is the header key for the name of the service sending the // request. This corresponds to the Request.Caller attribute. // This header is required. CallerHeader = "rpc-caller" // ServiceHeader is the header key for the name of the service to which // the request is being sent. This corresponds to the Request.Service attribute. // This header is required. ServiceHeader = "rpc-service" // ShardKeyHeader is the header key for the shard key used by the destined service // to shard the request. This corresponds to the Request.ShardKey attribute. // This header is optional. ShardKeyHeader = "rpc-shard-key" // RoutingKeyHeader is the header key for the traffic group responsible for // handling the request. This corresponds to the Request.RoutingKey attribute. // This header is optional. RoutingKeyHeader = "rpc-routing-key" // RoutingDelegateHeader is the header key for a service that can proxy the // destined service. This corresponds to the Request.RoutingDelegate attribute. // This header is optional. RoutingDelegateHeader = "rpc-routing-delegate" // EncodingHeader is the header key for the encoding used for the request body. // This corresponds to the Request.Encoding attribute. // If this is not set, content-type will attempt to be read for the encoding per // the gRPC wire format http://www.grpc.io/docs/guides/wire.html // For example, a content-type of "application/grpc+proto" will be intepreted // as the proto encoding. // This header is required unless content-type is set properly. EncodingHeader = "rpc-encoding" // ErrorNameHeader is the header key for the error name. ErrorNameHeader = "rpc-error-name" )
const UserAgent = "yarpc-go/" + yarpc.Version
UserAgent is the User-Agent that will be set for requests. http://www.grpc.io/docs/guides/wire.html#user-agents
Variables ¶
This section is empty.
Functions ¶
func TransportSpec ¶ added in v1.9.0
func TransportSpec(opts ...Option) yarpcconfig.TransportSpec
TransportSpec returns a TransportSpec for the gRPC transport.
See TransportConfig, InboundConfig, and OutboundConfig for details on the different configuration parameters supported by this Transport.
Any TransportOption, InboundOption, or OutboundOption may be passed to this function. These options will be applied BEFORE configuration parameters are interpreted. This allows configuration parameters to override Options provided to TransportSpec.
Types ¶
type ContextWrapper ¶ added in v1.14.0
type ContextWrapper struct {
// contains filtered or unexported fields
}
ContextWrapper wraps a context for grpc-go with the required headers for yarpc.
This is a convenience object for use when using grpc-go clients. You must set certain yarpc-specific headers when using native grpc-go clients calling into yarpc servers, and this object makes that simpler.
func NewContextWrapper ¶ added in v1.14.0
func NewContextWrapper() *ContextWrapper
NewContextWrapper returns a new ContextWrapper.
The only fields that a grpc-go client needs to set are caller and service. Encoding is also required if content-type is not set properly. See the documention on EncodingHeader.
func (*ContextWrapper) WithCaller ¶ added in v1.14.0
func (c *ContextWrapper) WithCaller(caller string) *ContextWrapper
WithCaller returns a new ContextWrapper with the given caller.
func (*ContextWrapper) WithEncoding ¶ added in v1.14.0
func (c *ContextWrapper) WithEncoding(encoding string) *ContextWrapper
WithEncoding returns a new ContextWrapper with the given encoding.
func (*ContextWrapper) WithRoutingDelegate ¶ added in v1.14.0
func (c *ContextWrapper) WithRoutingDelegate(routingDelegate string) *ContextWrapper
WithRoutingDelegate returns a new ContextWrapper with the given routing delegate.
func (*ContextWrapper) WithRoutingKey ¶ added in v1.14.0
func (c *ContextWrapper) WithRoutingKey(routingKey string) *ContextWrapper
WithRoutingKey returns a new ContextWrapper with the given routing key.
func (*ContextWrapper) WithService ¶ added in v1.14.0
func (c *ContextWrapper) WithService(service string) *ContextWrapper
WithService returns a new ContextWrapper with the given service.
func (*ContextWrapper) WithShardKey ¶ added in v1.14.0
func (c *ContextWrapper) WithShardKey(shardKey string) *ContextWrapper
WithShardKey returns a new ContextWrapper with the given shard key.
type Inbound ¶
type Inbound struct {
// contains filtered or unexported fields
}
Inbound is a grpc transport.Inbound.
func (*Inbound) Transports ¶
Transports implements transport.Inbound#Transports.
type InboundConfig ¶ added in v1.9.0
type InboundConfig struct { // Address to listen on. This field is required. Address string `config:"address,interpolate"` }
InboundConfig configures a gRPC Inbound.
inbounds:
grpc: address: ":80"
type InboundOption ¶
type InboundOption func(*inboundOptions)
InboundOption is an option for an inbound.
type Option ¶ added in v1.9.0
type Option interface {
// contains filtered or unexported methods
}
Option is an interface shared by TransportOption, InboundOption, and OutboundOption allowing either to be recognized by TransportSpec().
type Outbound ¶
type Outbound struct {
// contains filtered or unexported fields
}
Outbound is a transport.UnaryOutbound.
func (*Outbound) Call ¶
func (o *Outbound) Call(ctx context.Context, request *transport.Request) (*transport.Response, error)
Call implements transport.UnaryOutbound#Call.
func (*Outbound) Transports ¶
Transports implements transport.Inbound#Transports.
type OutboundConfig ¶ added in v1.9.0
type OutboundConfig struct { yarpcconfig.PeerChooser // Address to connect to if no peer options set. Address string `config:"address,interpolate"` }
OutboundConfig configures a gRPC Outbound.
outbounds:
myservice: grpc: address: ":80"
A gRPC outbound can also configure a peer list.
outbounds: myservice: grpc: round-robin: peers: - 127.0.0.1:8080 - 127.0.0.1:8081
type OutboundOption ¶
type OutboundOption func(*outboundOptions)
OutboundOption is an option for an outbound.
type Transport ¶ added in v1.9.0
type Transport struct {
// contains filtered or unexported fields
}
Transport is a grpc transport.Transport.
This currently does not have any additional functionality over creating an Inbound or Outbound separately, but may in the future.
func NewTransport ¶ added in v1.9.0
func NewTransport(options ...TransportOption) *Transport
NewTransport returns a new Transport.
func (*Transport) NewInbound ¶ added in v1.9.0
func (t *Transport) NewInbound(listener net.Listener, options ...InboundOption) *Inbound
NewInbound returns a new Inbound for the given listener.
func (*Transport) NewOutbound ¶ added in v1.14.0
func (t *Transport) NewOutbound(peerChooser peer.Chooser, options ...OutboundOption) *Outbound
NewOutbound returns a new Outbound for the given peer.Chooser.
func (*Transport) NewSingleOutbound ¶ added in v1.9.0
func (t *Transport) NewSingleOutbound(address string, options ...OutboundOption) *Outbound
NewSingleOutbound returns a new Outbound for the given adrress.
func (*Transport) ReleasePeer ¶ added in v1.14.0
func (t *Transport) ReleasePeer(peerIdentifier peer.Identifier, peerSubscriber peer.Subscriber) error
ReleasePeer releases the peer.
func (*Transport) RetainPeer ¶ added in v1.14.0
func (t *Transport) RetainPeer(peerIdentifier peer.Identifier, peerSubscriber peer.Subscriber) (peer.Peer, error)
RetainPeer retains the peer.
type TransportConfig ¶ added in v1.9.0
type TransportConfig struct {
Backoff yarpcconfig.Backoff `config:"backoff"`
}
TransportConfig configures a gRPC Transport. This is shared between all gRPC inbounds and outbounds of a Dispatcher.
transports: grpc: backoff: exponential: first: 10ms max: 30s
All parameters of TransportConfig are optional. This section may be omitted in the transports section.
type TransportOption ¶ added in v1.9.0
type TransportOption func(*transportOptions)
TransportOption is an option for a transport.
func BackoffStrategy ¶ added in v1.14.0
func BackoffStrategy(backoffStrategy backoff.Strategy) TransportOption
BackoffStrategy specifies the backoff strategy for delays between connection attempts for each peer.
The default is exponential backoff starting with 10ms fully jittered, doubling each attempt, with a maximum interval of 30s.
func ClientMaxRecvMsgSize ¶ added in v1.15.0
func ClientMaxRecvMsgSize(clientMaxRecvMsgSize int) TransportOption
ClientMaxRecvMsgSize is the maximum message size the client can receive.
The default is 4MB.
func ClientMaxSendMsgSize ¶ added in v1.15.0
func ClientMaxSendMsgSize(clientMaxSendMsgSize int) TransportOption
ClientMaxSendMsgSize is the maximum message size the client can send.
The default is unlimited.
func ServerMaxRecvMsgSize ¶ added in v1.15.0
func ServerMaxRecvMsgSize(serverMaxRecvMsgSize int) TransportOption
ServerMaxRecvMsgSize is the maximum message size the server can receive.
The default is 4MB.
func ServerMaxSendMsgSize ¶ added in v1.15.0
func ServerMaxSendMsgSize(serverMaxSendMsgSize int) TransportOption
ServerMaxSendMsgSize is the maximum message size the server can send.
The default is unlimited.
func Tracer ¶ added in v1.14.0
func Tracer(tracer opentracing.Tracer) TransportOption
Tracer specifies the tracer to use.
By default, opentracing.GlobalTracer() is used.