Documentation
¶
Index ¶
- Constants
- func CtxSubscriptionID(ctx context.Context) string
- func CtxTopic(ctx context.Context) string
- func GetMessageID(ctx context.Context) string
- func MarshalMessage(c codec.Codec, msg interface{}) (*pubsub.Message, error)
- func UnmarshalMessage(c codec.Codec, msg *pubsub.Message, dst interface{}) error
- type ChainHandler
- type Handler
- type HandlerFunc
- type MessageTyper
- type Middleware
- type Middlewares
- type Mux
- func (m *Mux) Close(ctx context.Context) error
- func (m *Mux) Run() error
- func (m *Mux) Subscribe(topic string, hf HandlerFunc)
- func (m *Mux) Subscription(sub *pubsub.Subscription, hf HandlerFunc, topic ...string)
- func (m *Mux) Use(middleware ...Middleware)
- func (m *Mux) With(middlewares ...Middleware) *Mux
- func (m *Mux) WithMaxHandlers(maxHandlers int) *Mux
- type Topic
- type TopicPublisher
Constants ¶
const MessageIDKey ctxKeyMessageID = 0
MessageIDKey is the key that holds the unique request ID in a request context.
Variables ¶
This section is empty.
Functions ¶
func CtxSubscriptionID ¶
CtxSubscriptionID gets the subscription id from the given context.
func GetMessageID ¶
GetMessageID returns a message ID from the given context if one is present. Returns the empty string if a message ID cannot be found.
func MarshalMessage ¶
MarshalMessage is a function that marshals input message structure into the pubsub.Message body.
Types ¶
type ChainHandler ¶
type ChainHandler struct {
Middlewares Middlewares
Endpoint Handler
// contains filtered or unexported fields
}
ChainHandler is a http.Handler with support for handler composition and execution.
type Handler ¶
Handler is an interface used by the Mux that is responsible for handling the Message.
func Acker ¶
Acker is a middleware that checks if the subsequent handlers returns an error and on success Ackes them. In case of failure it Nacks the message if it is possible.
func ContextMetadata ¶ added in v0.0.3
ContextMetadata sets up the metadata from the message in the context.
func Logger ¶
Logger is a middleware function that is used for trace logging incoming message on subscriptions.
func MessageID ¶
MessageID is a middleware function that generates new request id and puts it into message context, A message ID is a string of the form "host.example.com/random-0001", where "random" is a base62 random string that uniquely identifies this go process, and where the last number is an atomically incremented request counter. The concept and implementation of this request id is based on the brilliant golang library: github.com/go-chi/chi.
type HandlerFunc ¶
HandlerFunc is a function used to handle messages.
type MessageTyper ¶ added in v0.0.6
type MessageTyper interface {
MessageType() string
}
MessageTyper is an interface used by the event messages that defines the type of the message.
type Middleware ¶
Middleware is a middleware function type.
type Middlewares ¶
type Middlewares []Middleware
func (Middlewares) Handler ¶
func (mws Middlewares) Handler(h Handler) Handler
func (Middlewares) HandlerFunc ¶
func (mws Middlewares) HandlerFunc(h HandlerFunc) Handler
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
Mux is a subscriber router. It provides an easy interfaces for starting and listening on the subscriptions. Implements xservice.RunnerCloser interface.
func NewMux ¶
func NewMux() *Mux
NewMux creates a new mux that will register subscriptions using provided subscriber factory.
func (*Mux) Subscribe ¶
func (m *Mux) Subscribe(topic string, hf HandlerFunc)
Subscribe registers topic subscriber that handles the message using provided handler with given options.
func (*Mux) Subscription ¶
func (m *Mux) Subscription(sub *pubsub.Subscription, hf HandlerFunc, topic ...string)
Subscription registers subscription with specific handler. Optionally the topic name might be set for the logging and context passing purpose.
func (*Mux) Use ¶
func (m *Mux) Use(middleware ...Middleware)
Use provides middlewares to be used for all routes and children groups.
func (*Mux) With ¶
func (m *Mux) With(middlewares ...Middleware) *Mux
With sets the middlewares for the resultant Mux that would be used exclusively in its and it's children context.
func (*Mux) WithMaxHandlers ¶
WithMaxHandlers sets up the maximum concurrent handlers number for the resultant Mux that would be used exclusively in its and it's children context.
type Topic ¶
type Topic interface {
Send(ctx context.Context, m *pubsub.Message) error
Shutdown(ctx context.Context) error
ErrorAs(err error, i interface{}) bool
As(i interface{}) bool
}
Topic is the interface implementation of the pubsub.Topic. It allows to easily mockup the pubsub.Topic by replacing direct implementation.
type TopicPublisher ¶ added in v0.0.6
TopicPublisher is a structure responsible for publishing new topic messages.
func (*TopicPublisher) Publish ¶ added in v0.0.6
func (t *TopicPublisher) Publish(ctx context.Context, msg MessageTyper) error
Publish prepares pubsub.Message with the context stored metadata and publishes into given topic.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mockpubsub is a generated GoMock package.
|
Package mockpubsub is a generated GoMock package. |
|
pubsubmiddleware
|
|
|
natsmiddleware
module
|