client

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2018 License: Apache-2.0 Imports: 21 Imported by: 2

Documentation

Index

Constants

View Source
const (
	CLEAN_CHANNEL_SIZE = 64
)

Variables

View Source
var (
	// DefaultRetries is the default number of times a request is tried
	DefaultRetries = 1
	// DefaultRequestTimeout is the default request timeout
	DefaultRequestTimeout = time.Second * 5
	// DefaultPoolSize sets the connection pool size
	DefaultPoolSize = 0
	// DefaultPoolTTL sets the connection pool ttl
	DefaultPoolTTL = time.Minute

	DefaultRegistries = map[string]registry.NewRegistry{
		"zookeeper": zookeeper.NewConsumerZookeeperRegistry,
	}

	DefaultSelectors = map[string]selector.NewSelector{
		"cache": cache.NewSelector,
	}
)

Functions

This section is empty.

Types

type CallOption

type CallOption func(*CallOptions)

CallOption used by Call or Stream

func WithDialTimeout

func WithDialTimeout(d time.Duration) CallOption

WithDialTimeout is a CallOption which overrides that which set in Options.CallOptions

func WithRequestTimeout

func WithRequestTimeout(d time.Duration) CallOption

WithRequestTimeout is a CallOption which overrides that which set in Options.CallOptions

func WithRetries

func WithRetries(i int) CallOption

WithRetries is a CallOption which overrides that which set in Options.CallOptions

type CallOptions

type CallOptions struct {
	// Transport Dial Timeout
	DialTimeout time.Duration
	// Number of Call attempts
	Retries int
	// Request/Response timeout
	RequestTimeout time.Duration
	// cache selector address
	Next selector.Next
}

type Client

type Client interface {
	Options() Options
	NewRequest(group, version, service, method string, args interface{}, reqOpts ...RequestOption) Request
	Call(ctx context.Context, req Request, rsp interface{}, opts ...CallOption) error
	String() string
	Close()
}

Client is the interface used to make requests to services. It supports Request/Response via Transport and Publishing via the Broker. It also supports bidirectional streaming of requests.

func NewClient

func NewClient(opt ...Option) Client

creates a new client with the options passed in

type Option

type Option func(*Options)

Option used by the Client

func CodecType added in v0.2.0

func CodecType(t codec.CodecType) Option

Default content type of the client

func DialTimeout

func DialTimeout(d time.Duration) Option

Transport dial timeout

func PoolSize

func PoolSize(d int) Option

PoolSize sets the connection pool size

func PoolTTL

func PoolTTL(d time.Duration) Option

PoolSize sets the connection pool size

func Registry

func Registry(r registry.Registry) Option

Registry to find nodes for a given service

func RequestTimeout

func RequestTimeout(d time.Duration) Option

The request timeout. Should this be a Call Option?

func Retries

func Retries(i int) Option

Number of retries when making the request. Should this be a Call Option?

func Selector

func Selector(s selector.Selector) Option

Select is used to select a node to route a request to

func Transport

func Transport(t transport.Transport) Option

Transport to use for communication e.g http, rabbitmq, etc

type Options

type Options struct {
	// Used to select codec
	CodecType codec.CodecType

	Registry  registry.Registry
	Selector  selector.Selector
	Transport transport.Transport

	// Connection Pool
	PoolSize int
	PoolTTL  time.Duration

	// Default Call Options
	CallOptions CallOptions

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
	// contains filtered or unexported fields
}

type Request

type Request interface {
	Options() RequestOptions
	Protocol() string
	Version() string
	Method() string
	Args() interface{}
	ContentType() string
	ServiceConfig() registry.ServiceConfigIf
	// indicates whether the request will be a streaming one rather than unary
	Stream() bool
}

Request is the interface for a synchronous request used by Call or Stream

type RequestOption

type RequestOption func(*RequestOptions)

RequestOption used by NewRequest

func StreamingRequest

func StreamingRequest() RequestOption

type RequestOptions

type RequestOptions struct {
	Stream  bool
	Context context.Context
}

Jump to

Keyboard shortcuts

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