tchannel

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2017 License: MIT Imports: 16 Imported by: 58

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel added in v0.5.0

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 added in v1.0.0

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 added in v1.0.0

func (i *ChannelInbound) Channel() Channel

Channel returns the underlying Channel for this Inbound.

func (*ChannelInbound) Introspect added in v1.0.0

func (i *ChannelInbound) Introspect() introspection.InboundStatus

Introspect returns the state of the inbound for introspection purposes.

func (*ChannelInbound) IsRunning added in v1.0.0

func (i *ChannelInbound) IsRunning() bool

IsRunning returns whether the ChannelInbound is running.

func (*ChannelInbound) SetRouter added in v1.0.0

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 added in v1.0.0

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 added in v1.0.0

func (i *ChannelInbound) Stop() error

Stop stops the TChannel outbound. This currently does nothing.

func (*ChannelInbound) Transports added in v1.0.0

func (i *ChannelInbound) Transports() []transport.Transport

Transports returns a slice containing the ChannelInbound's underlying ChannelTransport.

type ChannelOutbound added in v1.0.0

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 added in v1.0.0

Call sends an RPC over this TChannel outbound.

func (*ChannelOutbound) Introspect added in v1.0.0

Introspect returns basic status about this outbound.

func (*ChannelOutbound) IsRunning added in v1.0.0

func (o *ChannelOutbound) IsRunning() bool

IsRunning returns whether the ChannelOutbound is running.

func (*ChannelOutbound) Start added in v1.0.0

func (o *ChannelOutbound) Start() error

Start starts the TChannel outbound.

func (*ChannelOutbound) Stop added in v1.0.0

func (o *ChannelOutbound) Stop() error

Stop stops the TChannel outbound.

func (*ChannelOutbound) Transports added in v1.0.0

func (o *ChannelOutbound) Transports() []transport.Transport

Transports returns the underlying TChannel Transport for this outbound.

type ChannelTransport added in v1.0.0

type ChannelTransport struct {
	// contains filtered or unexported fields
}

ChannelTransport maintains TChannel peers and creates inbounds and outbounds for TChannel.

func NewChannelTransport added in v1.0.0

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 added in v1.0.0

func (t *ChannelTransport) Channel() Channel

Channel returns the underlying TChannel "Channel" instance.

func (*ChannelTransport) IsRunning added in v1.0.0

func (t *ChannelTransport) IsRunning() bool

IsRunning returns whether the ChannelTransport is running.

func (*ChannelTransport) ListenAddr added in v1.0.0

func (t *ChannelTransport) ListenAddr() string

ListenAddr exposes the listen address of the transport.

func (*ChannelTransport) NewInbound added in v1.0.0

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 added in v1.0.0

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 added in v1.0.0

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 added in v1.0.0

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 added in v1.0.0

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 added in v1.0.0

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 added in v1.0.0

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 added in v1.0.0

func Tracer(tracer opentracing.Tracer) TransportOption

Tracer specifies the request tracer used for RPCs passing through the TChannel transport.

func WithChannel added in v1.0.0

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL