Documentation ¶
Overview ¶
Package nproto contains high level types and functions.
Index ¶
- func NewIncomingContextWithMD(ctx context.Context, md MD) context.Context
- func NewOutgoingContextWithMD(ctx context.Context, md MD) context.Context
- type MD
- type MetaData
- type MsgAsyncPublisher
- type MsgAsyncPublisherFunc
- type MsgAsyncPublisherMiddleware
- type MsgHandler
- type MsgMiddleware
- type MsgPublisher
- type MsgPublisherFunc
- type MsgPublisherMiddleware
- type MsgSubscriber
- type MsgSubscriberWithMWs
- type PBPublisher
- type RPCClient
- type RPCClientWithMWs
- type RPCHandler
- type RPCMethod
- type RPCMiddleware
- type RPCServer
- type RPCServerWithMWs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewIncomingContextWithMD ¶ added in v0.5.0
NewIncomingContextWithMD creates a new context with incoming 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).
func MDFromIncomingContext ¶ added in v0.5.0
MDFromIncomingCont extracts incoming MD from context or nil if not found.
func MDFromOutgoingContext ¶ added in v0.5.0
MDFromOutgoingContext extracts outgoing MD from context or nil if not found.
type MetaData ¶
MetaData is the default implementation of MD. nil is a valid value.
func NewMetaDataFromMD ¶ added in v0.5.0
NewMetaDataFromMD creates a MetaData from MD.
func NewMetaDataPairs ¶
NewMetaDataPairs creates a MetaData from key/value pairs. len(kv) must be even.
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
MsgAsyncPublisherFunc is an adapter to allow the use of ordinary functions as MsgAsyncPublisher.
func (MsgAsyncPublisherFunc) Publish ¶ added in v0.5.0
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 ¶
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
MsgPublisherFunc is an adapter to allow th use of ordinary functions as MsgPublisher.
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.
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 ¶
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. |