Documentation
¶
Overview ¶
Package noop is the messagequeue publisher and consumer pair for a service with no broker. Publish and PublishAsync accept every message and drop it, every messagequeue.PublishOption included, and the providers hand back further noops, so a wiring graph that fans out into a dozen topics builds without a queue behind any of them.
Consume keeps the messagequeue.Consumer contract: it runs until ctx is done. There is nothing to poll, so it blocks on the context and nothing else — no handler is ever invoked and nothing is ever sent on errs — but a service that blocks on Consume as its run loop serves until it is cancelled, exactly as it would with a real broker, rather than exiting at startup.
messagequeue/config builds either provider for the "noop" provider name, which has to be given.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Consumer ¶
type Consumer struct{}
Consumer is the no-op messagequeue.Consumer.
func (*Consumer) Consume ¶
Consume blocks until ctx is done, which is the messagequeue.Consumer contract. It has nothing to poll, so blocking on the context is all it does: the handler is never called and errs is never written to.
It matters that it blocks rather than returning. A service whose run loop is Consume treats a return as "the consumer stopped", so a noop that returned immediately took the process down at startup — with no error to explain it, because there was no error.
type ConsumerProvider ¶
type ConsumerProvider struct{}
ConsumerProvider is the no-op messagequeue.ConsumerProvider.
func NewConsumerProvider ¶
func NewConsumerProvider() *ConsumerProvider
NewConsumerProvider returns a no-op ConsumerProvider.
func (*ConsumerProvider) Close ¶
func (n *ConsumerProvider) Close()
func (*ConsumerProvider) NewConsumer ¶
func (n *ConsumerProvider) NewConsumer(context.Context, string, messagequeue.ConsumerFunc) (messagequeue.Consumer, error)
type Publisher ¶
type Publisher struct{}
Publisher is the no-op messagequeue.Publisher.
func NewPublisher ¶
func NewPublisher() *Publisher
NewPublisher returns a no-op Publisher.
Example ¶
package main
import (
"context"
"fmt"
"github.com/primandproper/platform-go/v10/messagequeue/noop"
)
func main() {
pub := noop.NewPublisher()
defer pub.Stop()
err := pub.Publish(context.Background(), map[string]string{"event": "user.created"})
fmt.Println(err)
}
Output: <nil>
func (*Publisher) Publish ¶
func (n *Publisher) Publish(context.Context, any, ...messagequeue.PublishOption) error
func (*Publisher) PublishAsync ¶
func (n *Publisher) PublishAsync(context.Context, any, ...messagequeue.PublishOption)
type PublisherProvider ¶
type PublisherProvider struct{}
PublisherProvider is the no-op messagequeue.PublisherProvider.
func NewPublisherProvider ¶
func NewPublisherProvider() *PublisherProvider
NewPublisherProvider returns a no-op PublisherProvider.
Example ¶
package main
import (
"context"
"fmt"
"github.com/primandproper/platform-go/v10/messagequeue/noop"
)
func main() {
provider := noop.NewPublisherProvider()
defer provider.Close()
pub, err := provider.NewPublisher(context.Background(), "user-events")
if err != nil {
panic(err)
}
fmt.Println(pub != nil)
}
Output: true
func (*PublisherProvider) Close ¶
func (n *PublisherProvider) Close()
func (*PublisherProvider) NewPublisher ¶
func (n *PublisherProvider) NewPublisher(context.Context, string) (messagequeue.Publisher, error)