tchannel

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2017 License: MIT Imports: 21 Imported by: 0

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
	RootPeers() *tchannel.RootPeerList
	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. If you have a YARPC peer.Chooser, use the unqualified tchannel.Transport instead (instead of the tchannel.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.ChannelTransport. If you have a YARPC peer.Chooser, use the unqualified tchannel.Transport instead (instead of the tchannel.ChannelTransport).

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. If you have a YARPC peer.Chooser, use the unqualified tchannel.Transport instead.

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. Use NewTransport and its NewOutbound to support YARPC peer.Choosers.

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. If you have a YARPC peer.Chooser, use the unqualified tchannel.NewInbound instead. There should only be one inbound for TChannel since all outbounds send the listening port over non-ephemeral connections so a service can deduplicate locally- and remotely-initiated persistent connections.

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. In a future version of YARPC, Stop will block until the underlying channel has closed completely.

type Inbound

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

Inbound receives YARPC requests over TChannel. It may be constructed using the NewInbound method on a tchannel.Transport.

Example
package main

import (
	"log"

	"go.uber.org/yarpc"
	"go.uber.org/yarpc/transport/tchannel"
)

func main() {
	transport, err := tchannel.NewTransport(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 (*Inbound) Introspect added in v1.4.0

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

Introspect returns the state of the inbound for introspection purposes.

func (*Inbound) IsRunning added in v1.4.0

func (i *Inbound) IsRunning() bool

IsRunning returns whether the Inbound is running.

func (*Inbound) SetRouter added in v1.4.0

func (i *Inbound) 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 (*Inbound) Start added in v1.4.0

func (i *Inbound) 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 (*Inbound) Stop added in v1.4.0

func (i *Inbound) Stop() error

Stop stops the TChannel outbound. This currently does nothing.

func (*Inbound) Transports added in v1.4.0

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

Transports returns a slice containing the Inbound's underlying Transport.

type Outbound added in v1.4.0

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

Outbound 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.NewTransport(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 (*Outbound) Call added in v1.4.0

Call sends an RPC over this TChannel outbound.

func (*Outbound) Introspect added in v1.4.0

func (o *Outbound) Introspect() introspection.OutboundStatus

Introspect returns basic status about this outbound.

func (*Outbound) IsRunning added in v1.4.0

func (o *Outbound) IsRunning() bool

IsRunning returns whether the ChannelOutbound is running.

func (*Outbound) Start added in v1.4.0

func (o *Outbound) Start() error

Start starts the TChannel outbound.

func (*Outbound) Stop added in v1.4.0

func (o *Outbound) Stop() error

Stop stops the TChannel outbound.

func (*Outbound) Transports added in v1.4.0

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

Transports returns the underlying TChannel Transport for this outbound.

type Transport added in v1.4.0

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

Transport is a TChannel transport suitable for use with YARPC's peer selection system. The transport implements peer.Transport so multiple peer.List implementations can retain and release shared peers. The transport implements transport.Transport so it is suitable for lifecycle management.

func NewTransport added in v1.4.0

func NewTransport(opts ...TransportOption) (*Transport, error)

NewTransport 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.

func (*Transport) IsRunning added in v1.4.0

func (t *Transport) IsRunning() bool

IsRunning returns whether the TChannel transport is running.

func (*Transport) ListenAddr added in v1.4.0

func (t *Transport) ListenAddr() string

ListenAddr exposes the listen address of the transport.

func (*Transport) NewInbound added in v1.4.0

func (t *Transport) NewInbound() *Inbound

NewInbound returns a new TChannel inbound backed by a shared TChannel transport. There should only be one inbound for TChannel since all outbounds send the listening port over non-ephemeral connections so a service can deduplicate locally- and remotely-initiated persistent connections.

func (*Transport) NewOutbound added in v1.4.0

func (t *Transport) NewOutbound(chooser peer.Chooser) *Outbound

NewOutbound builds a new TChannel outbound that selects a peer for each request using the given peer chooser.

func (*Transport) NewSingleOutbound added in v1.4.0

func (t *Transport) NewSingleOutbound(addr string) *Outbound

NewSingleOutbound builds a new TChannel outbound always using the peer with the given address.

func (*Transport) ReleasePeer added in v1.4.0

func (t *Transport) ReleasePeer(pid peer.Identifier, sub peer.Subscriber) error

ReleasePeer releases a peer from the peer.Subscriber and removes that peer from the Transport if nothing is listening to it.

func (*Transport) RetainPeer added in v1.4.0

func (t *Transport) RetainPeer(pid peer.Identifier, sub peer.Subscriber) (peer.Peer, error)

RetainPeer adds a peer subscriber (typically a peer chooser) and causes the transport to maintain persistent connections with that peer.

func (*Transport) Start added in v1.4.0

func (t *Transport) 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 (*Transport) Stop added in v1.4.0

func (t *Transport) Stop() error

Stop stops the TChannel transport. It starts rejecting incoming requests and draining connections before closing them. In a future version of YARPC, Stop will block 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