client

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2016 License: Apache-2.0 Imports: 16 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
)

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

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Client

type Client interface {
	Init(...Option) error
	Options() Options
	NewJsonRequest(service, method string, req 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 bidiectional 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 Codec

func Codec(contentType string, c codec.NewCodec) Option

Codec to be used to encode/decode requests for a given content type

func ContentType

func ContentType(ct string) 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
	ContentType string

	// Plugged interfaces
	Codecs    map[string]codec.NewCodec
	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
}

type Request

type Request interface {
	Service() string
	Method() string
	ContentType() string
	Request() interface{}
	// 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

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Streamer

type Streamer interface {
	Context() context.Context
	Request() Request
	Send(interface{}) error
	Recv(interface{}) error
	Error() error
	Close() error
}

Streamer is the inteface for a bidirectional synchronous stream

Jump to

Keyboard shortcuts

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