@@ -11,9 +11,10 @@ import (
11
11
"github.com/ThreeDotsLabs/watermill/message"
12
12
)
13
13
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 = "*"
17
18
18
19
// Config holds the GoChannel Pub/Sub's configuration options.
19
20
type Config struct {
@@ -32,8 +33,13 @@ type Config struct {
32
33
BlockPublishUntilSubscriberAck bool
33
34
34
35
// 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
37
43
}
38
44
39
45
// GoChannel is the simplest Pub/Sub implementation.
@@ -69,6 +75,10 @@ func NewGoChannel(config Config, logger watermill.LoggerAdapter) *GoChannel {
69
75
logger = watermill.NopLogger {}
70
76
}
71
77
78
+ if config .EnableNoSubscribersFallback && config .NoSubscribersFallbackTopic == "" {
79
+ config .NoSubscribersFallbackTopic = NoSubscribersFallbackDefaultTopic
80
+ }
81
+
72
82
return & GoChannel {
73
83
config : config ,
74
84
@@ -149,12 +159,12 @@ func (g *GoChannel) sendMessage(topic string, message *message.Message) (<-chan
149
159
logFields := watermill.LogFields {"message_uuid" : message .UUID , "topic" : topic }
150
160
151
161
if len (subscribers ) == 0 {
152
- if ! g .config .EnableFallback {
162
+ if ! g .config .EnableNoSubscribersFallback {
153
163
return g .handleNoSubscribers (ackedBySubscribers , logFields )
154
164
}
155
165
156
166
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 {
158
168
return g .handleNoSubscribers (ackedBySubscribers , logFields )
159
169
}
160
170
}
0 commit comments