rpcbus

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRequestTimeout is returned when request timeout-ed.
	ErrRequestTimeout = errors.New("timeout-ed request")

	// ErrMethodExists is returned when method is already registered.
	ErrMethodExists = errors.New("method exists already")

	// ErrInvalidRequestChan is returned method is bound to nil chan.
	ErrInvalidRequestChan = errors.New("invalid request channel")

	// DefaultTimeout is used when 0 timeout is set on calling a method.
	DefaultTimeout = 5 * time.Second
)

Functions

This section is empty.

Types

type ErrMethodNotExists

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

ErrMethodNotExists is returned when calling an unregistered method.

func (*ErrMethodNotExists) Error added in v0.4.0

func (e *ErrMethodNotExists) Error() string

Error obeys the error interface.

type RPCBus

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

RPCBus is a request–response mechanism for internal communication between node components/subsystems. Under the hood this is long-polling method based on "chan chan" technique.

func New

func New() *RPCBus

New creates an RPCBus instance.

func (*RPCBus) Call

func (bus *RPCBus) Call(t topics.Topic, req Request, timeOut time.Duration) (interface{}, error)

Call runs a long-polling technique to request from the method Consumer to run the corresponding procedure and return a result or timeout.

func (*RPCBus) Close

func (bus *RPCBus) Close()

Close the RPCBus by resetting the registry.

func (*RPCBus) Deregister added in v0.4.0

func (bus *RPCBus) Deregister(t topics.Topic)

Deregister removes a handler channel from a method.

func (*RPCBus) Register

func (bus *RPCBus) Register(t topics.Topic, req chan<- Request) error

Register registers a method and binds it to a handler channel. methodName must be unique per node instance. If not, returns err.

type Request

type Request struct {
	Params   interface{}
	RespChan chan Response
}

Request is the request object forwarded to the RPC endpoint.

func EmptyRequest added in v0.3.0

func EmptyRequest() Request

EmptyRequest returns a Request instance with no parameters.

func NewRequest

func NewRequest(p interface{}) Request

NewRequest builds a new request with params. It creates the response channel under the hood.

type Response

type Response struct {
	Resp interface{}
	Err  error
}

Response is the response to the request forwarded to the RPC endpoint.

func NewResponse added in v0.3.0

func NewResponse(p interface{}, err error) Response

NewResponse builds a new response.

Jump to

Keyboard shortcuts

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