watermill icon indicating copy to clipboard operation
watermill copied to clipboard

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

Open flc1125 opened this issue 1 year ago • 0 comments

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.

flc1125 avatar Jan 26 '24 08:01 flc1125