zrpc

package module
v0.0.0-...-59d56d3 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2015 License: MIT Imports: 23 Imported by: 0

README

zrpc

RPC framework using ZeroMQ and Protocol Buffers

Documentation

Overview

Package zrpc is a generated protocol buffer package.

It is generated from these files:

request.proto
response.proto

It has these top-level messages:

Request

Index

Constants

View Source
const (
	RequestTimeout = time.Second * 2
	RouterURL      = "inproc://router"
)
View Source
const (
	EndpointReconnectInterval = time.Second * 5
)

Variables

View Source
var (
	ErrShutdown           = errors.New("zrpc: connection is shut down")
	ErrMessageMismatch    = errors.New("zrpc: received message ID did not match the one sent")
	ErrTimeout            = errors.New("zrpc: request timeout")
	ErrCancel             = errors.New("zrpc: request cancelled")
	ErrServiceNameMissing = errors.New("zrpc: missing service name (hint: pass it through the context)")
)

Functions

func CheckError

func CheckError(err error, statusCode int) bool

CheckError checks if the given error is of the passed status code

func DefaultError

func DefaultError(e zrpcError) string

A default implementation of the Error method of the error interface.

func NewBadRequestError

func NewBadRequestError(msg string) zrpcError

func NewClientError

func NewClientError(msg string, statusCode int) zrpcError

NewClientError creates and returns a client error (without stack trace)

func NewConflictError

func NewConflictError(msg string) zrpcError

func NewError

func NewError(msg string, statusCode int) zrpcError

This returns a new zrpcBaseError initialized with the given message and the current stack trace.

func NewExpiredError

func NewExpiredError(msg string) zrpcError

func NewForbiddenError

func NewForbiddenError(msg string) zrpcError

func NewInternalError

func NewInternalError(msg string) zrpcError

func NewNotFoundError

func NewNotFoundError(msg string) zrpcError

func NewNotImplementedError

func NewNotImplementedError(msg string) zrpcError

func NewServiceNameContext

func NewServiceNameContext(ctx context.Context, serviceName string) context.Context

NewServiceNameContext returns a new context carrying a service name

func ServiceNameFromContext

func ServiceNameFromContext(ctx context.Context) (string, bool)

ServiceNameFromContext extracts a servicename from passed context

func StackTrace

func StackTrace() (current, context string)

This returns the current stack trace string. NOTE: the stack creation code is excluded from the stack trace.

func WrapError

func WrapError(err error, msg string, statusCode int) zrpcError

WrapError wraps another error in a new zrpcBaseError.

Types

type Call

type Call struct {
	Service string        // The service to send to
	Req     proto.Message // The request to the function.
	Resp    proto.Message // The reply from the function.
	// contains filtered or unexported fields
}

Call represents an active call to a service.

type Client

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

Client is used to interact with a service

func Dial

func Dial(address ...string) (*Client, error)

Dial connects to a zrpc server at the specified network address Protocol is limited to tcp

func NewClient

func NewClient(serviceName string, watcher watch.Watcher) *Client

NewClient returns a new Client to handle requests to the service at the other end of the connection. A watcher is used to get updates about service endpoints

func NewClientWithConnection

func NewClientWithConnection(ctx *zmq.Context, conn *zmq.Socket) *Client

NewClientWithConnection returns a new Client to handle requests to the set of services at the other end of the connection. An existing connection in the form of a zmq socket together with the zmq context they were created with is used

func (*Client) Call

func (client *Client) Call(ctx context.Context, req proto.Message, resp proto.Message) error

Call sends the request, waits for it to complete, and returns its error status.

func (*Client) Close

func (client *Client) Close() error

type Request

type Request struct {
	UUID             []byte  `protobuf:"bytes,1,opt" json:"UUID,omitempty"`
	Path             *string `protobuf:"bytes,2,opt,name=path" json:"path,omitempty"`
	Payload          []byte  `protobuf:"bytes,3,opt,name=payload" json:"payload,omitempty"`
	Expires          *int64  `protobuf:"varint,4,opt,name=expires" json:"expires,omitempty"`
	XXX_unrecognized []byte  `json:"-"`
}

Request is an envelope for sending a request from a client to a service

func (*Request) GetExpires

func (m *Request) GetExpires() int64

func (*Request) GetPath

func (m *Request) GetPath() string

func (*Request) GetPayload

func (m *Request) GetPayload() []byte

func (*Request) GetUUID

func (m *Request) GetUUID() []byte

func (*Request) ProtoMessage

func (*Request) ProtoMessage()

func (*Request) Reset

func (m *Request) Reset()

func (*Request) String

func (m *Request) String() string

type Response

type Response struct {
	UUID             []byte          `protobuf:"bytes,1,opt" json:"UUID,omitempty"`
	Path             *string         `protobuf:"bytes,2,opt,name=path" json:"path,omitempty"`
	Payload          []byte          `protobuf:"bytes,3,opt,name=payload" json:"payload,omitempty"`
	StatusCode       *uint32         `protobuf:"varint,4,opt,name=status_code" json:"status_code,omitempty"`
	Error            *Response_Error `protobuf:"bytes,5,opt,name=error" json:"error,omitempty"`
	XXX_unrecognized []byte          `json:"-"`
}

Response is an envelope for a service responding to a request from a client

func (*Response) GetError

func (m *Response) GetError() *Response_Error

func (*Response) GetPath

func (m *Response) GetPath() string

func (*Response) GetPayload

func (m *Response) GetPayload() []byte

func (*Response) GetStatusCode

func (m *Response) GetStatusCode() uint32

func (*Response) GetUUID

func (m *Response) GetUUID() []byte

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) Reset

func (m *Response) Reset()

func (*Response) String

func (m *Response) String() string

type Response_Error

type Response_Error struct {
	Message          *string `protobuf:"bytes,1,opt,name=message" json:"message,omitempty"`
	XXX_unrecognized []byte  `json:"-"`
}

func (*Response_Error) GetMessage

func (m *Response_Error) GetMessage() string

func (*Response_Error) ProtoMessage

func (*Response_Error) ProtoMessage()

func (*Response_Error) Reset

func (m *Response_Error) Reset()

func (*Response_Error) String

func (m *Response_Error) String() string

type Server

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

Server represents an RPC Server.

func NewServer

func NewServer(workers int) *Server

NewServer returns a new Server.

func (*Server) Close

func (server *Server) Close()

Close closes the server, usually deferred upon starting it

func (*Server) Register

func (server *Server) Register(rcvr interface{}) error

Register publishes in the server the set of methods of the receiver value that satisfy the following conditions:

  • exported method
  • two arguments, both of exported type
  • the second argument is a pointer
  • one return value, of type error

It returns an error if the receiver is not an exported type or has no suitable methods. It also logs the error using package log. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.

func (*Server) RegisterName

func (server *Server) RegisterName(name string, rcvr interface{}) error

RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.

func (*Server) Start

func (server *Server) Start(addr string)

Start registers a zmq endpoint at passed address answering requests for registered services

Directories

Path Synopsis
examples
reverseservice/reverseservicepb
Package reverseservicepb is a generated protocol buffer package.
Package reverseservicepb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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