Documentation
¶
Overview ¶
Package pubsubabs provides an abstraction layer over the `pubsub` PublisherClient types to allow testing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetPublishResult ¶
func SetPublishResult(r *IPublishResult, sid string, err error)
SetPublishResult sets the server ID and error for a publish result and closes the Ready channel.
Types ¶
type ErrorStop ¶
type ErrorStop interface {
// Error returns the error that caused the publisher client to terminate. The
// error returned here may contain more context than PublishResult errors. The
// return value may be nil if Stop() was called.
Error() error
// Stop sends all remaining published messages and closes publish streams.
// Returns once all outstanding messages have been sent or have failed to be
// sent. Stop should be called when the client is no longer required.
Stop()
}
ErrorStop defines the Stop and Error methods.
type IPublishResult ¶
type IPublishResult struct {
// contains filtered or unexported fields
}
IPublishResult is a copy from the internal pubsub packgage. All the code below has been copied from "cloud.google.com/go/internal/pubsub" Copyright 2020 Google LLC
func NewPublishResult ¶
func NewPublishResult() *IPublishResult
NewPublishResult creates a PublishResult.
func (*IPublishResult) Get ¶
func (r *IPublishResult) Get(ctx context.Context) (serverID string, err error)
Get returns the server-generated message ID and/or error result of a Publish call. Get blocks until the Publish call completes or the context is done.
func (*IPublishResult) Ready ¶
func (r *IPublishResult) Ready() <-chan struct{}
Ready returns a channel that is closed when the result is ready. When the Ready channel is closed, Get is guaranteed not to block.
type PublishResult ¶
type PublishResult interface {
// Get returns the server-generated message ID and/or error result of a Publish call.
// Get blocks until the Publish call completes or the context is done.
Get(ctx context.Context) (serverID string, err error)
// Ready returns a channel that is closed when the result is ready.
// When the Ready channel is closed, Get is guaranteed not to block.
Ready() <-chan struct{}
}
PublishResult abstracts the pubsub.PublishResult type.
type Publisher ¶
type Publisher interface {
ErrorStop
// Publish publishes `msg` to the topic asynchronously. Messages are batched and
// sent according to the client's PublishSettings. Publish never blocks.
//
// Publish returns a non-nil PublishResult which will be ready when the
// message has been sent (or has failed to be sent) to the server. Retry-able
// errors are automatically handled. If a PublishResult returns an error, this
// indicates that the publisher client encountered a fatal error and can no
// longer be used. Fatal errors should be manually inspected and the cause
// resolved. A new publisher client instance must be created to republish failed
// messages.
//
// Once Stop() has been called or the publisher client has failed permanently
// due to an error, future calls to Publish will immediately return a
// PublishResult with error ErrPublisherStopped.
//
// Error() returns the error that caused the publisher client to terminate and
// may contain more context than the error returned by PublishResult.
Publish(ctx context.Context, msg *pubsub.Message) PublishResult
}
Publisher defines an abstracted interface that can be used for mocking or testing purposes. It wraps a Publisher client.
func Wrap ¶
func Wrap(c PublisherClient) Publisher
Wrap returns an abstracted Publisher from a PublisherClient.
type PublisherClient ¶
type PublisherClient interface {
ErrorStop
Publish(ctx context.Context, msg *pubsub.Message) *pubsub.PublishResult
}
PublisherClient represents a PubSub PublisherClient.