nproto

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package nproto contains high level types and functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewIncomingContextWithMD added in v0.5.0

func NewIncomingContextWithMD(ctx context.Context, md MD) context.Context

NewIncomingContextWithMD creates a new context with incoming MD attached.

func NewOutgoingContextWithMD added in v0.5.0

func NewOutgoingContextWithMD(ctx context.Context, md MD) context.Context

NewOutgoingContextWithMD creates a new context with outgoing MD attached.

Types

type MD added in v0.5.0

type MD interface {
	// Keys iterates all keys in MD.
	Keys(cb func(string) error) error

	// HasKey returns true if MD contains the specified key.
	HasKey(key string) bool

	// Values returns the list of values associated with the specified key or
	// nil if not exists. NOTE: Don't modify the returned slice and its content.
	Values(key string) [][]byte
}

MD is used to carry extra key/value context data (meta data) from outgoing side to incoming side. Each key (utf8 string) has a list of values (any bytes) associated. MD should be immutable once attached to context. Create a new one if you want to modify. (just like context.WithValue).

var (
	// EmptyMD is an empty MD.
	EmptyMD MD = (MetaData)(nil)
)

func MDFromIncomingContext added in v0.5.0

func MDFromIncomingContext(ctx context.Context) MD

MDFromIncomingCont extracts incoming MD from context or nil if not found.

func MDFromOutgoingContext added in v0.5.0

func MDFromOutgoingContext(ctx context.Context) MD

MDFromOutgoingContext extracts outgoing MD from context or nil if not found.

type MetaData

type MetaData map[string][][]byte

MetaData is the default implementation of MD. nil is a valid value.

func NewMetaDataFromMD added in v0.5.0

func NewMetaDataFromMD(md MD) MetaData

NewMetaDataFromMD creates a MetaData from MD.

func NewMetaDataPairs

func NewMetaDataPairs(kv ...string) MetaData

NewMetaDataPairs creates a MetaData from key/value pairs. len(kv) must be even.

func (MetaData) HasKey added in v0.5.0

func (md MetaData) HasKey(key string) bool

HasKey implements MD interface.

func (MetaData) Keys added in v0.5.0

func (md MetaData) Keys(cb func(string) error) error

Keys implements MD interface.

func (MetaData) Values added in v0.5.0

func (md MetaData) Values(key string) [][]byte

Values implements MD interface.

type MsgAsyncPublisher

type MsgAsyncPublisher interface {
	// PublishAsync publishes a message to the given subject asynchronously.
	// The final result is returned by `cb` if PublishAsync returns nil.
	// `cb` must be called exactly once in this case.
	PublishAsync(ctx context.Context, subject string, msgData []byte, cb func(error)) error
}

MsgAsyncPublisher is similar to MsgPublisher but in async manner. It's trivial to implement MsgPublisher, see MsgAsyncPublisherFunc.

func NewMsgAsyncPublisherWithMWs added in v0.9.0

func NewMsgAsyncPublisherWithMWs(publisher MsgAsyncPublisher, mws ...MsgAsyncPublisherMiddleware) MsgAsyncPublisher

NewMsgAsyncPublisherWithMWs wraps a MsgAsyncPublisher with middlewares.

type MsgAsyncPublisherFunc added in v0.5.0

type MsgAsyncPublisherFunc func(context.Context, string, []byte, func(error)) error

MsgAsyncPublisherFunc is an adapter to allow the use of ordinary functions as MsgAsyncPublisher.

func (MsgAsyncPublisherFunc) Publish added in v0.5.0

func (fn MsgAsyncPublisherFunc) Publish(ctx context.Context, subject string, msgData []byte) error

Publish implements MsgAsyncPublisher interface.

func (MsgAsyncPublisherFunc) PublishAsync added in v0.5.0

func (fn MsgAsyncPublisherFunc) PublishAsync(ctx context.Context, subject string, msgData []byte, cb func(error)) error

PublishAsync implements MsgAsyncPublisher interface.

type MsgAsyncPublisherMiddleware added in v0.9.0

type MsgAsyncPublisherMiddleware func(MsgAsyncPublisherFunc) MsgAsyncPublisherFunc

MsgAsyncPublisherMiddleware wraps MsgAsyncPublisherFunc into another one.

type MsgHandler

type MsgHandler func(context.Context, []byte) error

MsgHandler handles messages. A message should be redelivered if the handler returns an error.

type MsgMiddleware

type MsgMiddleware func(string, string, MsgHandler) MsgHandler

MsgMiddleware wraps a MsgHandler into another one. The params are (subject, queue, handler).

type MsgPublisher

type MsgPublisher interface {
	// Publish publishes a message to the given subject. It returns nil if success.
	Publish(ctx context.Context, subject string, msgData []byte) error
}

MsgPublisher is used to publish messages reliably, e.g. at least once delivery.

func NewMsgPublisherWithMWs added in v0.9.0

func NewMsgPublisherWithMWs(publisher MsgPublisher, mws ...MsgPublisherMiddleware) MsgPublisher

NewMsgPublisherWithMWs wraps a MsgPublisher with middlewares.

type MsgPublisherFunc added in v0.9.0

type MsgPublisherFunc func(context.Context, string, []byte) error

MsgPublisherFunc is an adapter to allow th use of ordinary functions as MsgPublisher.

func (MsgPublisherFunc) Publish added in v0.9.0

func (fn MsgPublisherFunc) Publish(ctx context.Context, subject string, msgData []byte) error

Publish implements MsgPublisher interface.

type MsgPublisherMiddleware added in v0.9.0

type MsgPublisherMiddleware func(MsgPublisherFunc) MsgPublisherFunc

MsgPublisherMiddleware wraps MsgPublisherFunc into another one.

type MsgSubscriber

type MsgSubscriber interface {
	// Subscribe subscribes to a given subject. One subject can have many queues.
	// In normal case (excpet message redelivery) each message will be delivered to
	// one member of each queue.
	// Order of messages is not guaranteed since redelivery.
	Subscribe(subject, queue string, handler MsgHandler, opts ...interface{}) error
}

MsgSubscriber is used to consume messages.

type MsgSubscriberWithMWs added in v0.9.0

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

MsgSubscriberWithMWs wraps a MsgSubscriber with middlewares.

func NewMsgSubscriberWithMWs added in v0.9.0

func NewMsgSubscriberWithMWs(subscriber MsgSubscriber, mws ...MsgMiddleware) *MsgSubscriberWithMWs

NewMsgSubscriberWithMWs creates a new MsgSubscriberWithMWs.

func (*MsgSubscriberWithMWs) Subscribe added in v0.9.0

func (subscriber *MsgSubscriberWithMWs) Subscribe(subject, queue string, handler MsgHandler, opts ...interface{}) error

Subscribe implements MsgSubscriber interface.

type PBPublisher added in v0.5.0

type PBPublisher struct {
	Publisher MsgPublisher
}

PBPublisher is used to publish protobuf message.

func (*PBPublisher) Publish added in v0.5.0

func (p *PBPublisher) Publish(ctx context.Context, subject string, msg proto.Message) error

Publish publishes a protobuf message.

type RPCClient

type RPCClient interface {
	// MakeHandler creates a RPCHandler for a given method of a service.
	MakeHandler(svcName string, method *RPCMethod) RPCHandler
}

RPCClient is used to invoke rpc services.

type RPCClientWithMWs added in v0.9.0

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

RPCClientWithMWs wraps an RPCClient with RPCMiddlewares.

func NewRPCClientWithMWs added in v0.9.0

func NewRPCClientWithMWs(client RPCClient, mws ...RPCMiddleware) *RPCClientWithMWs

NewRPCClientWithMWs creates a new RPCClientWithMWs.

func (*RPCClientWithMWs) MakeHandler added in v0.9.0

func (client *RPCClientWithMWs) MakeHandler(svcName string, method *RPCMethod) RPCHandler

MakeHandler implements RPCClient interface.

type RPCHandler

type RPCHandler func(context.Context, proto.Message) (proto.Message, error)

RPCHandler do the real job. RPCHandler can be client side or server side.

type RPCMethod

type RPCMethod struct {
	// Name is the name of this method.
	Name string
	// NewInput is used to generate a new input message.
	NewInput func() proto.Message
	// NewOutput is used to generate a new output message.
	NewOutput func() proto.Message
}

RPCMethod contains meta information of a given method.

type RPCMiddleware

type RPCMiddleware func(string, *RPCMethod, RPCHandler) RPCHandler

RPCMiddleware wraps an RPCHandler into another one. The params are (svcName, method, handler).

type RPCServer

type RPCServer interface {
	// RegistSvc regist a service with given method set and associated handlers.
	RegistSvc(svcName string, methods map[*RPCMethod]RPCHandler) error

	// DeregistSvc deregist a service.
	DeregistSvc(svcName string) error
}

RPCServer is used to serve rpc services.

type RPCServerWithMWs added in v0.9.0

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

RPCServerWithMWs wraps an RPCServer with RPCMiddlewares.

func NewRPCServerWithMWs added in v0.9.0

func NewRPCServerWithMWs(server RPCServer, mws ...RPCMiddleware) *RPCServerWithMWs

NewRPCServerWithMWs creates a new RPCServerWithMWs.

func (*RPCServerWithMWs) DeregistSvc added in v0.9.0

func (server *RPCServerWithMWs) DeregistSvc(svcName string) error

DeregistSvc implements RPCServer interface.

func (*RPCServerWithMWs) RegistSvc added in v0.9.0

func (server *RPCServerWithMWs) RegistSvc(svcName string, methods map[*RPCMethod]RPCHandler) error

RegistSvc implements RPCServer interface. Which will wrap methods with middlewares.

Directories

Path Synopsis
Package binlogmsg contains BinlogMsgPipe which is used as a publisher pipeline from MySQL-8 to downstream publisher.
Package binlogmsg contains BinlogMsgPipe which is used as a publisher pipeline from MySQL-8 to downstream publisher.
Package dbpipe contains DBMsgPublisherPipe which is used as a publisher pipeline from RDBMS to downstream publisher (deprecating).
Package dbpipe contains DBMsgPublisherPipe which is used as a publisher pipeline from RDBMS to downstream publisher (deprecating).
Package natsrpc contains NatsRPCServer/NatsRPCClient which implement nproto.RPCServer and nproto.RPCClient.
Package natsrpc contains NatsRPCServer/NatsRPCClient which implement nproto.RPCServer and nproto.RPCClient.
Package stanmsg contains DurConn which implements nproto.MsgPublisher/nproto.MsgAsyncPublisher and nproto.MsgSubscriber.
Package stanmsg contains DurConn which implements nproto.MsgPublisher/nproto.MsgAsyncPublisher and nproto.MsgSubscriber.
Package tracing contains middlewares for RPCServer/RPCClient/MsgPublisher/MsgSubscriber to add opentracing support.
Package tracing contains middlewares for RPCServer/RPCClient/MsgPublisher/MsgSubscriber to add opentracing support.

Jump to

Keyboard shortcuts

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