rpc

package
v0.0.0-...-e3fe981 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Client rpc client side.

func NewClient

func NewClient(publisher *nsq.Producer, reqTopic, rspTopic string) *Client

NewClient creates new rpc client. publisher will be used for sending request on reqTopic. rspTopic will be send in each message envelope, server will reply on that topic.

func (*Client) Call

func (c *Client) Call(ctx context.Context, typ string, req []byte) ([]byte, string, error)

func (*Client) CallTopic

func (c *Client) CallTopic(ctx context.Context, reqTopic, typ string, req []byte) ([]byte, string, error)

Call entry point for request from application.

func (*Client) HandleMessage

func (c *Client) HandleMessage(m *nsq.Message) error

HandleMessage accepts incoming server reponses.

type Envelope

type Envelope struct {
	// method to call on the server side
	Method string `json:"m,omitempty"`
	// nsq topic to send reply to
	ReplyTo string `json:"r,omitempty"`
	// connection between request and response
	CorrelationID uint32 `json:"c,omitempty"`
	// unix timestamp when message expires, after that should be dropped
	ExpiresAt int64 `json:"x,omitempty"`
	// applicationn error reponse, if server side failed and Body is missing
	Error string `json:"e,omitempty"`
	// message body
	Body []byte `json:"-"`
}

Envelope arround message for request response communication over nsq.

func Decode

func Decode(buf []byte) (*Envelope, error)

Decode decodes envelope from bytes.

func (*Envelope) Encode

func (m *Envelope) Encode() []byte

Encode encodes envelope into bytes for putting on wire.

func (*Envelope) Expired

func (m *Envelope) Expired() bool

Expired returns true if message expired.

func (*Envelope) Reply

func (m *Envelope) Reply(body []byte, err error) *Envelope

Reply creates reply Envelope from request Envelope.

type Server

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

Server rpc server side.

func NewServer

func NewServer(ctx context.Context, srv appServer, producer *nsq.Producer) *Server

NewServer creates new rpc server for appServer. producer will be used for sending replies.

func (*Server) HandleMessage

func (s *Server) HandleMessage(m *nsq.Message) error

HandleMessage server side handler.

Jump to

Keyboard shortcuts

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