Skip to content

feat(manager): Add a manager to support unified driver switching#420

Closed
flc1125 wants to merge 1 commit intoThreeDotsLabs:masterfrom
flc1125:feat-watermill
Closed

feat(manager): Add a manager to support unified driver switching#420
flc1125 wants to merge 1 commit intoThreeDotsLabs:masterfrom
flc1125:feat-watermill

Conversation

@flc1125
Copy link
Copy Markdown

@flc1125 flc1125 commented Jan 26, 2024

For Example:

package main

import (
	"context"

	"github.com/ThreeDotsLabs/watermill"
	"github.com/ThreeDotsLabs/watermill/manager"
	"github.com/ThreeDotsLabs/watermill/message"
	"github.com/ThreeDotsLabs/watermill/pubsub/gochannel"
)

func main() {
	m := manager.New(gochannel.NewGoChannel(
		gochannel.Config{},
		watermill.NewStdLogger(false, false),
	))

	m.Register("another", gochannel.NewGoChannel(
		gochannel.Config{},
		watermill.NewStdLogger(false, false),
	))
	// or other pubsub drivers, e.g.: nas/kafka...

	m.Publish("topic", message.NewMessage(watermill.NewUUID(), []byte("Hello, world!")))
	m.Use().Publish("topic", message.NewMessage(watermill.NewUUID(), []byte("Hello, world!")))
	m.Use("another").Publish("topic", message.NewMessage(watermill.NewUUID(), []byte("Hello, world!")))

	m.Subscribe(context.Background(), "topic")
	m.Use().Subscribe(context.Background(), "topic")
	m.Use("another").Subscribe(context.Background(), "topic")
}

Originally, I wanted to put it under the https://github.com/ThreeDotsLabs/watermill package, but there is a circular dependency in the current architecture. So, I created a manager package.

@m110
Copy link
Copy Markdown
Member

m110 commented Aug 20, 2025

Thanks for contributing @flc1125!

The code looks good to me, although we decided to avoid adding more APIs for working with the Pub/Subs to keep it straightforward and explicit. It's short enough that someone could keep it in their project if they want. Alternatively, it could be a good candidate for a separate repository. :)

@m110 m110 closed this Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants