github.com/wfusion/gofusion@v1.1.14/mq/gochannel.go (about) 1 package mq 2 3 import ( 4 "context" 5 6 "github.com/wfusion/gofusion/common/infra/watermill" 7 "github.com/wfusion/gofusion/common/infra/watermill/pubsub/gochannel" 8 "github.com/wfusion/gofusion/config" 9 ) 10 11 func newGoChannel(ctx context.Context, appName, name string, conf *Conf, logger watermill.LoggerAdapter) ( 12 pub Publisher, sub Subscriber) { 13 cfg := gochannel.Config{ 14 OutputChannelBuffer: int64(conf.ConsumerConcurrency), 15 Persistent: conf.Persistent, 16 ConsumerGroup: conf.ConsumerGroup, 17 BlockPublishUntilSubscriberAck: false, 18 AppID: config.Use(appName).AppName(), 19 } 20 21 native := gochannel.NewGoChannel(cfg, logger) 22 if conf.Producer { 23 pub = &goChannel{ 24 abstractMQ: newPub(ctx, native, appName, name, conf, logger), 25 ch: native, 26 } 27 } 28 29 if conf.Consumer { 30 sub = &goChannel{ 31 abstractMQ: newSub(ctx, native, appName, name, conf, logger), 32 ch: native, 33 } 34 } 35 return 36 } 37 38 type goChannel struct { 39 *abstractMQ 40 ch *gochannel.GoChannel 41 } 42 43 func (g *goChannel) close() (err error) { return g.ch.Close() }