@@ -11,9 +11,10 @@ import (
1111 "github.com/ThreeDotsLabs/watermill/message"
1212)
1313
14- // NoSubscribersFallbackTopic is the fallback topic messages without any subscribers will be sent to.
15- // This is used if the `EnableFallback` configuration option is enabled.
16- const NoSubscribersFallbackTopic = "*"
14+ // NoSubscribersFallbackDefaultTopic is the default fallback topic messages without any subscribers
15+ // will be sent to – it is used if the `EnableNoSubscribersFallback` option is enabled and no
16+ // fallback topic is configured via the `NoSubscribersFallbackTopic` option.
17+ const NoSubscribersFallbackDefaultTopic = "*"
1718
1819// Config holds the GoChannel Pub/Sub's configuration options.
1920type Config struct {
@@ -32,8 +33,13 @@ type Config struct {
3233 BlockPublishUntilSubscriberAck bool
3334
3435 // When true, messages sent to a topic without any subscribers will be sent to the
35- // subscribers of the `*` topic.
36- EnableFallback bool
36+ // subscribers of the fallback topic (configured via `NoSubscribersFallbackTopic` option).
37+ EnableNoSubscribersFallback bool
38+
39+ // NoSubscribersFallbackTopic is the fallback topic messages without any subscribers will be sent to.
40+ // This is used if the `EnableNoSubscribersFallback` configuration option is enabled.
41+ // If it's not set then `*` is used by default.
42+ NoSubscribersFallbackTopic string
3743}
3844
3945// GoChannel is the simplest Pub/Sub implementation.
@@ -69,6 +75,10 @@ func NewGoChannel(config Config, logger watermill.LoggerAdapter) *GoChannel {
6975 logger = watermill.NopLogger {}
7076 }
7177
78+ if config .EnableNoSubscribersFallback && config .NoSubscribersFallbackTopic == "" {
79+ config .NoSubscribersFallbackTopic = NoSubscribersFallbackDefaultTopic
80+ }
81+
7282 return & GoChannel {
7383 config : config ,
7484
@@ -149,12 +159,12 @@ func (g *GoChannel) sendMessage(topic string, message *message.Message) (<-chan
149159 logFields := watermill.LogFields {"message_uuid" : message .UUID , "topic" : topic }
150160
151161 if len (subscribers ) == 0 {
152- if ! g .config .EnableFallback {
162+ if ! g .config .EnableNoSubscribersFallback {
153163 return g .handleNoSubscribers (ackedBySubscribers , logFields )
154164 }
155165
156166 g .logger .Debug ("No subscribers to send the message to, trying the fallback subscribers" , logFields )
157- if subscribers = g .topicSubscribers (NoSubscribersFallbackTopic ); len (subscribers ) == 0 {
167+ if subscribers = g .topicSubscribers (g . config . NoSubscribersFallbackTopic ); len (subscribers ) == 0 {
158168 return g .handleNoSubscribers (ackedBySubscribers , logFields )
159169 }
160170 }
0 commit comments