Documentation ¶
Overview ¶
Package tchannel implements a YARPC transport based on the TChannel protocol. The TChannel transport provides support for Unary RPCs only.
Usage ¶
A ChannelTransport must be constructed to use this transport. You can provide an existing TChannel Channel to construct the Channel transport.
ch := getTChannelChannel() tchannelTransport, err := tchannel.NewChannelTransport(tchannel.WithChannel(ch))
Alternatively, you can let YARPC own and manage the TChannel Channel for you by providing the service name. Note that this is the name of the local service, not the name of the service you will be sending requests to.
tchannelTransport, err := tchannel.NewChannelTransport(tchannel.ServiceName("myservice"))
To serve a YARPC application over TChannel, pass a TChannel inbound in your yarpc.Config.
myInbound := tchannelTransport.NewInbound() dispatcher := yarpc.NewDispatcher(yarpc.Config{ Name: "myservice", Inbounds: yarpc.Inbounds{myInbound}, })
To make requests to a YARPC application that supports TChannel, pass a TChannel outbound in your yarpc.Config.
myserviceOutbound := tchannelTransport.NewOutbound() dispatcher := yarpc.NewDispatcher(yarpc.Config{ Name: "myservice", Outbounds: yarpc.OUtbounds{ {Unary: myserviceOutbound}, }, })
Index ¶
- type Channel
- type ChannelInbound
- func (i *ChannelInbound) Channel() Channel
- func (i *ChannelInbound) Introspect() introspection.InboundStatus
- func (i *ChannelInbound) IsRunning() bool
- func (i *ChannelInbound) SetRouter(router transport.Router)
- func (i *ChannelInbound) Start() error
- func (i *ChannelInbound) Stop() error
- func (i *ChannelInbound) Transports() []transport.Transport
- type ChannelOutbound
- func (o *ChannelOutbound) Call(ctx context.Context, req *transport.Request) (*transport.Response, error)
- func (o *ChannelOutbound) Introspect() introspection.OutboundStatus
- func (o *ChannelOutbound) IsRunning() bool
- func (o *ChannelOutbound) Start() error
- func (o *ChannelOutbound) Stop() error
- func (o *ChannelOutbound) Transports() []transport.Transport
- type ChannelTransport
- func (t *ChannelTransport) Channel() Channel
- func (t *ChannelTransport) IsRunning() bool
- func (t *ChannelTransport) ListenAddr() string
- func (t *ChannelTransport) NewInbound() *ChannelInbound
- func (t *ChannelTransport) NewOutbound() *ChannelOutbound
- func (t *ChannelTransport) NewSingleOutbound(addr string) *ChannelOutbound
- func (t *ChannelTransport) Start() error
- func (t *ChannelTransport) Stop() error
- type TransportOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel interface { BeginCall( ctx context.Context, hostPort, serviceName, methodName string, callOptions *tchannel.CallOptions, ) (*tchannel.OutboundCall, error) Close() GetSubChannel(serviceName string, opts ...tchannel.SubChannelOption) *tchannel.SubChannel ListenAndServe(hostPort string) error PeerInfo() tchannel.LocalPeerInfo ServiceName() string State() tchannel.ChannelState }
Channel is the interface exposed by TChannel. The TChannel transport for YARPC is built on top of this interface.
See https://godoc.org/github.com/uber/tchannel-go#Channel for more information about these methods.
type ChannelInbound ¶
type ChannelInbound struct {
// contains filtered or unexported fields
}
ChannelInbound receives YARPC requests over TChannel. It may be constructed using the NewInbound method on ChannelTransport.
Example ¶
package main import ( "log" "go.uber.org/yarpc" "go.uber.org/yarpc/transport/tchannel" ) func main() { transport, err := tchannel.NewChannelTransport(tchannel.ServiceName("myservice")) if err != nil { log.Fatal(err) } dispatcher := yarpc.NewDispatcher(yarpc.Config{ Name: "myservice", Inbounds: yarpc.Inbounds{transport.NewInbound()}, }) if err := dispatcher.Start(); err != nil { log.Fatal(err) } defer dispatcher.Stop() }
Output:
func (*ChannelInbound) Channel ¶
func (i *ChannelInbound) Channel() Channel
Channel returns the underlying Channel for this Inbound.
func (*ChannelInbound) Introspect ¶
func (i *ChannelInbound) Introspect() introspection.InboundStatus
Introspect returns the state of the inbound for introspection purposes.
func (*ChannelInbound) IsRunning ¶
func (i *ChannelInbound) IsRunning() bool
IsRunning returns whether the ChannelInbound is running.
func (*ChannelInbound) SetRouter ¶
func (i *ChannelInbound) SetRouter(router transport.Router)
SetRouter configures a router to handle incoming requests. This satisfies the transport.Inbound interface, and would be called by a dispatcher when it starts.
func (*ChannelInbound) Start ¶
func (i *ChannelInbound) Start() error
Start starts this Inbound. Note that this does not start listening for connections; that occurs when you start the underlying ChannelTransport is started.
func (*ChannelInbound) Stop ¶
func (i *ChannelInbound) Stop() error
Stop stops the TChannel outbound. This currently does nothing.
func (*ChannelInbound) Transports ¶
func (i *ChannelInbound) Transports() []transport.Transport
Transports returns a slice containing the ChannelInbound's underlying ChannelTransport.
type ChannelOutbound ¶
type ChannelOutbound struct {
// contains filtered or unexported fields
}
ChannelOutbound sends YARPC requests over TChannel. It may be constructed using the NewOutbound or NewSingleOutbound methods on the TChannel Transport.
Example ¶
package main import ( "log" "go.uber.org/yarpc" "go.uber.org/yarpc/transport/tchannel" ) func main() { transport, err := tchannel.NewChannelTransport(tchannel.ServiceName("myclient")) if err != nil { log.Fatal(err) } dispatcher := yarpc.NewDispatcher(yarpc.Config{ Name: "myclient", Outbounds: yarpc.Outbounds{ "myservice": {Unary: transport.NewOutbound()}, }, }) if err := dispatcher.Start(); err != nil { log.Fatal(err) } defer dispatcher.Stop() }
Output:
Example (Single) ¶
package main import ( "log" "go.uber.org/yarpc" "go.uber.org/yarpc/transport/tchannel" ) func main() { transport, err := tchannel.NewChannelTransport(tchannel.ServiceName("myclient")) if err != nil { log.Fatal(err) } dispatcher := yarpc.NewDispatcher(yarpc.Config{ Name: "myclient", Outbounds: yarpc.Outbounds{ "myservice": {Unary: transport.NewSingleOutbound("127.0.0.0:4040")}, }, }) if err := dispatcher.Start(); err != nil { log.Fatal(err) } defer dispatcher.Stop() }
Output:
func (*ChannelOutbound) Call ¶
func (o *ChannelOutbound) Call(ctx context.Context, req *transport.Request) (*transport.Response, error)
Call sends an RPC over this TChannel outbound.
func (*ChannelOutbound) Introspect ¶
func (o *ChannelOutbound) Introspect() introspection.OutboundStatus
Introspect returns basic status about this outbound.
func (*ChannelOutbound) IsRunning ¶
func (o *ChannelOutbound) IsRunning() bool
IsRunning returns whether the ChannelOutbound is running.
func (*ChannelOutbound) Start ¶
func (o *ChannelOutbound) Start() error
Start starts the TChannel outbound.
func (*ChannelOutbound) Stop ¶
func (o *ChannelOutbound) Stop() error
Stop stops the TChannel outbound.
func (*ChannelOutbound) Transports ¶
func (o *ChannelOutbound) Transports() []transport.Transport
Transports returns the underlying TChannel Transport for this outbound.
type ChannelTransport ¶
type ChannelTransport struct {
// contains filtered or unexported fields
}
ChannelTransport maintains TChannel peers and creates inbounds and outbounds for TChannel.
func NewChannelTransport ¶
func NewChannelTransport(opts ...TransportOption) (*ChannelTransport, error)
NewChannelTransport is a YARPC transport that facilitates sending and receiving YARPC requests through TChannel. It uses a shared TChannel Channel for both, incoming and outgoing requests, ensuring reuse of connections and other resources.
Either the local service name (with the ServiceName option) or a user-owned TChannel (with the WithChannel option) MUST be specified.
ChannelTransport uses the underlying TChannel Channel for load balancing and peer managament. A future version of YARPC will include support for peer.Chooser-based TChannel transports.
func (*ChannelTransport) Channel ¶
func (t *ChannelTransport) Channel() Channel
Channel returns the underlying TChannel "Channel" instance.
func (*ChannelTransport) IsRunning ¶
func (t *ChannelTransport) IsRunning() bool
IsRunning returns whether the ChannelTransport is running.
func (*ChannelTransport) ListenAddr ¶
func (t *ChannelTransport) ListenAddr() string
ListenAddr exposes the listen address of the transport.
func (*ChannelTransport) NewInbound ¶
func (t *ChannelTransport) NewInbound() *ChannelInbound
NewInbound returns a new TChannel inbound backed by a shared TChannel transport. The returned ChannelInbound does not support peer.Chooser and uses TChannel's own internal load balancing peer selection.
func (*ChannelTransport) NewOutbound ¶
func (t *ChannelTransport) NewOutbound() *ChannelOutbound
NewOutbound builds a new TChannel outbound using the transport's shared channel to make requests to any connected peer.
func (*ChannelTransport) NewSingleOutbound ¶
func (t *ChannelTransport) NewSingleOutbound(addr string) *ChannelOutbound
NewSingleOutbound builds a new TChannel outbound using the transport's shared channel to a specific peer.
func (*ChannelTransport) Start ¶
func (t *ChannelTransport) Start() error
Start starts the TChannel transport. This starts making connections and accepting inbound requests. All inbounds must have been assigned a router to accept inbound requests before this is called.
func (*ChannelTransport) Stop ¶
func (t *ChannelTransport) Stop() error
Stop stops the TChannel transport. It starts rejecting incoming requests and draining connections before closing them. Stop blocks until the underlying channel has closed completely.
type TransportOption ¶
type TransportOption func(*transportConfig)
TransportOption customizes the behavior of a TChannel Transport.
func ListenAddr ¶
func ListenAddr(addr string) TransportOption
ListenAddr specifies the port the TChannel should listen on. This defaults to ":0" (all interfaces, OS-assigned port).
transport := NewChannelTransport(ServiceName("myservice"), ListenAddr(":4040"))
This option has no effect if WithChannel was used and the TChannel was already listening.
func ServiceName ¶
func ServiceName(name string) TransportOption
ServiceName specifies the name of the current service for the YARPC-owned TChannel Channel. If the WithChannel option is not specified, the TChannel Transport will build its own TChannel Chanel and use this name for that Channel.
This option MUST be specified if WithChannel was not used. Note that this is the name of the LOCAL service, not the service you are trying to send requests to.
This option has no effect if WithChannel was used.
func Tracer ¶
func Tracer(tracer opentracing.Tracer) TransportOption
Tracer specifies the request tracer used for RPCs passing through the TChannel transport.
func WithChannel ¶
func WithChannel(ch Channel) TransportOption
WithChannel specifies the TChannel Channel to use to send and receive YARPC requests. The instance may already have handlers registered against it; these will be left unchanged.
If this option is not passed, the Transport will build and manage its own Channel. The behavior of that Tchannel may be customized using the ListenAddr and ServiceName options.