Title here
Summary here
// ...
// GoChannel is the simplest Pub/Sub implementation.
// It is based on Golang's channels which are sent within the process.
//
// GoChannel has no global state,
// that means that you need to use the same instance for Publishing and Subscribing!
//
// When GoChannel is persistent, messages order is not guaranteed.
type GoChannel struct {
// ...
Full source: github.com/ThreeDotsLabs/watermill/pubsub/gochannel/pubsub.go
You can find a fully functional example with Go Channels in the Watermill examples .
Feature | Implements | Note |
---|---|---|
ConsumerGroups | no | |
ExactlyOnceDelivery | yes | |
GuaranteedOrder | yes | |
Persistent | no |
You can inject configuration via the constructor.
// ...
func NewGoChannel(config Config, logger watermill.LoggerAdapter) *GoChannel {
if logger == nil {
logger = watermill.NopLogger{}
}
return &GoChannel{
config: config,
subscribers: make(map[string][]*subscriber),
subscribersByTopicLock: sync.Map{},
logger: logger.With(watermill.LogFields{
// ...
Full source: github.com/ThreeDotsLabs/watermill/pubsub/gochannel/pubsub.go
// ...
// Publish in GoChannel is NOT blocking until all consumers consume.
// Messages will be sent in background.
//
// Messages may be persisted or not, depending on persistent attribute.
func (g *GoChannel) Publish(topic string, messages ...*message.Message) error {
// ...
Full source: github.com/ThreeDotsLabs/watermill/pubsub/gochannel/pubsub.go
// ...
// Subscribe returns channel to which all published messages are sent.
// Messages are not persisted. If there are no subscribers and message is produced it will be gone.
//
// There are no consumer groups support etc. Every consumer will receive every produced message.
func (g *GoChannel) Subscribe(ctx context.Context, topic string) (<-chan *message.Message, error) {
// ...
Full source: github.com/ThreeDotsLabs/watermill/pubsub/gochannel/pubsub.go
No marshaling is needed when sending messages within the process.