Skip to content

Repository files navigation

core-pubsub

A pubsub module for package Core built upon Watermill.

BuildGo ReferencecodecovGo Report CardSourcegraph

Example

package pubsub_test
import (
"context""fmt""time""github.com/DoNewsCode/core"
pubsub "github.com/DoNewsCode/core-pubsub""github.com/ThreeDotsLabs/watermill""github.com/ThreeDotsLabs/watermill/message""github.com/ThreeDotsLabs/watermill/pubsub/gochannel"
)
typeMyModulestruct {
goch*gochannel.GoChannelcancelfunc()
}
func (m*MyModule) ProvidePubSub(router*message.Router) {
router.AddNoPublisherHandler(
"example",
"example-in",
m.goch,
func(msg*message.Message) error {
fmt.Println(string(msg.Payload))
m.cancel()
returnnil
},
)
}
funcExample() {
ctx, cancel:=context.WithCancel(context.Background())
defercancel()
goch:=gochannel.NewGoChannel(gochannel.Config{}, watermill.NopLogger{})
module:=MyModule{goch, cancel}
c:=core.Default(core.WithInline("log.level", "none"))
c.AddModuleFunc(pubsub.New)
c.AddModule(&module)
gofunc() {
time.Sleep(time.Second)
goch.Publish("example-in", message.NewMessage(watermill.NewUUID(), message.Payload("foo")))
}()
c.Serve(ctx)
// Output:// foo
}

About

A pubsub module for package core.

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages