From 29f58c4a0ea725622fbaa3b75fb653d024e4d44c Mon Sep 17 00:00:00 2001 From: Daniel Lohse Date: Sun, 7 May 2023 16:57:27 +0200 Subject: [PATCH] Add `EnableFallback` configuration option and const for topic --- pubsub/gochannel/pubsub.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pubsub/gochannel/pubsub.go b/pubsub/gochannel/pubsub.go index 4770ad725..c607b19e2 100644 --- a/pubsub/gochannel/pubsub.go +++ b/pubsub/gochannel/pubsub.go @@ -11,6 +11,10 @@ import ( "github.com/ThreeDotsLabs/watermill/message" ) +// NoSubscribersFallbackTopic is the fallback topic messages without any subscribers will be sent to. +// This is used if the `EnableFallback` configuration option is enabled. +const NoSubscribersFallbackTopic = "*" + // Config holds the GoChannel Pub/Sub's configuration options. type Config struct { // Output channel buffer size. @@ -26,6 +30,10 @@ type Config struct { // When true, Publish will block until subscriber Ack's the message. // If there are no subscribers, Publish will not block (also when Persistent is true). BlockPublishUntilSubscriberAck bool + + // When true, messages sent to a topic without any subscribers will be sent to the + // subscribers of the `*` topic. + EnableFallback bool } // GoChannel is the simplest Pub/Sub implementation.