Skip to content

Commit 8978679

Browse files
authored
Add AddConsumerHandler (rename AddNoPublisherHandler) (#611)
* AddConsumerHandle The current AddNoPublisherHandler name can be confusing, especially since it's the one most often used.
1 parent abb87c9 commit 8978679

File tree

12 files changed

+54
-34
lines changed

12 files changed

+54
-34
lines changed

components/cqrs/command_processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func (p CommandProcessor) addHandlerToRouter(r *message.Router, handler CommandH
299299
return nil, errors.Wrap(err, "cannot create subscriber for command processor")
300300
}
301301

302-
return r.AddNoPublisherHandler(
302+
return r.AddConsumerHandler(
303303
handlerName,
304304
topicName,
305305
subscriber,

components/cqrs/event_processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func addHandlerToRouter(logger watermill.LoggerAdapter, r *message.Router, handl
303303

304304
logger.Debug("Adding CQRS event handler to router", nil)
305305

306-
return r.AddNoPublisherHandler(
306+
return r.AddConsumerHandler(
307307
handlerName,
308308
topicName,
309309
subscriber,

components/fanin/fanin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestFanIn(t *testing.T) {
5656
receivedMessages := make(chan string, expectedNumberOfMessages)
5757

5858
for i := 0; i < workersCount; i++ {
59-
router.AddNoPublisherHandler(
59+
router.AddConsumerHandler(
6060
fmt.Sprintf("worker-%v", i),
6161
downstreamTopic,
6262
pubsub,

components/forwarder/forwarder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func NewForwarder(subscriberIn message.Subscriber, publisherOut message.Publishe
8585

8686
f := &Forwarder{router, publisherOut, logger, config}
8787

88-
handler := router.AddNoPublisherHandler(
88+
handler := router.AddConsumerHandler(
8989
"events_forwarder",
9090
config.ForwarderTopic,
9191
subscriberIn,

components/requeuer/requeuer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func NewRequeuer(
110110
config: config,
111111
}
112112

113-
config.Router.AddNoPublisherHandler(
113+
config.Router.AddConsumerHandler(
114114
"requeuer",
115115
config.SubscribeTopic,
116116
config.Subscriber,

components/requeuer/requeuer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestRequeue(t *testing.T) {
5252
lock := sync.Mutex{}
5353
counter := 0
5454

55-
router.AddNoPublisherHandler(
55+
router.AddConsumerHandler(
5656
"test",
5757
"test",
5858
pubSub,

docs/content/docs/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ Any messages returned from the handler function will be published to the given p
322322
*Note: the example above uses one `pubSub` argument for both the subscriber and publisher.
323323
It's because we use the `GoChannel` implementation, which is a simple in-memory Pub/Sub.*
324324

325-
Alternatively, if you don't plan to publish messages from within the handler, you can use the simpler `AddNoPublisherHandler` method.
325+
Alternatively, if you don't plan to publish messages from within the handler, you can use the simpler `AddConsumerHandler` method.
326326

327327
{{% load-snippet-partial file="src-link/_examples/basic/3-router/main.go" first_line_contains="AddNoPublisherHandler" last_line_contains=")" padding_after="0" %}}
328328

docs/content/docs/messages-router.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ Next, you have to add a new handler with `Router.AddHandler`:
3434
See an example usage from [Getting Started]({{< ref "/docs/getting-started#using-messages-router" >}}):
3535
{{% load-snippet-partial file="src-link/_examples/basic/3-router/main.go" first_line_contains="// AddHandler returns a handler" last_line_contains="return h(message)" padding_after="3" %}}
3636

37-
## No publisher handler
37+
## Consumer handler
3838

39-
Not every handler will produce new messages. You can add this kind of handler by using `Router.AddNoPublisherHandler`:
39+
Not every handler will produce new messages. You can add this kind of handler by using `Router.AddConsumerHandler`:
4040

4141
{{% load-snippet-partial file="src-link/message/router.go" first_line_contains="// AddNoPublisherHandler" last_line_contains=") {" padding_after="0" %}}
4242

@@ -81,7 +81,7 @@ If the timeout is reached, `Close()` will return an error.
8181
## Adding handler after the router has started
8282

8383
You can add a new handler while the router is already running.
84-
To do that, you need to call `AddNoPublisherHandler` or `AddHandler` and call `RunHandlers`.
84+
To do that, you need to call `AddConsumerHandler` or `AddHandler` and call `RunHandlers`.
8585

8686
{{% load-snippet-partial file="src-link/message/router.go" first_line_contains="// RunHandlers" last_line_contains="func (r *Router) RunHandlers" padding_after="0" %}}
8787

message/router.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func (d DuplicateHandlerNameError) Error() string {
265265
//
266266
// publishTopic is a topic to which router will produce messages returned by handlerFunc.
267267
// When handler needs to publish to multiple topics,
268-
// it is recommended to use AddNoPublisherHandler and inject a Publisher or implement middleware
268+
// it is recommended to use AddConsumerHandler and inject a Publisher or implement middleware
269269
// which will catch messages and publish to topic based on metadata for example.
270270
//
271271
// If handler is added while router is already running, you need to explicitly call RunHandlers().
@@ -329,9 +329,8 @@ func (r *Router) AddHandler(
329329
}
330330
}
331331

332-
// AddNoPublisherHandler adds a new handler.
333-
// This handler cannot return messages.
334-
// When message is returned it will occur an error and Nack will be sent.
332+
// AddConsumerHandler adds a new handler that does not return any messages.
333+
// It can publish messages by directly using a Publisher.
335334
//
336335
// handlerName must be unique. For now, it is used only for debugging.
337336
//
@@ -340,7 +339,7 @@ func (r *Router) AddHandler(
340339
// subscriber is Subscriber from which messages will be consumed.
341340
//
342341
// If handler is added while router is already running, you need to explicitly call RunHandlers().
343-
func (r *Router) AddNoPublisherHandler(
342+
func (r *Router) AddConsumerHandler(
344343
handlerName string,
345344
subscribeTopic string,
346345
subscriber Subscriber,
@@ -353,6 +352,27 @@ func (r *Router) AddNoPublisherHandler(
353352
return r.AddHandler(handlerName, subscribeTopic, subscriber, "", disabledPublisher{}, handlerFuncAdapter)
354353
}
355354

355+
// AddNoPublisherHandler adds a new handler.
356+
// This handler cannot return messages.
357+
//
358+
// handlerName must be unique. For now, it is used only for debugging.
359+
//
360+
// subscribeTopic is a topic from which handler will receive messages.
361+
//
362+
// subscriber is Subscriber from which messages will be consumed.
363+
//
364+
// If handler is added while router is already running, you need to explicitly call RunHandlers().
365+
//
366+
// Deprecated: use AddConsumerHandler instead.
367+
func (r *Router) AddNoPublisherHandler(
368+
handlerName string,
369+
subscribeTopic string,
370+
subscriber Subscriber,
371+
handlerFunc NoPublishHandlerFunc,
372+
) *Handler {
373+
return r.AddConsumerHandler(handlerName, subscribeTopic, subscriber, handlerFunc)
374+
}
375+
356376
// Run runs all plugins and handlers and starts subscribing to provided topics.
357377
// This call is blocking while the router is running.
358378
//

message/router/middleware/poison_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func TestPoisonQueue_context_values(t *testing.T) {
125125
require.NoError(t, err)
126126
router.AddMiddleware(pq)
127127

128-
router.AddNoPublisherHandler("handler_name", "test", pubSub, func(msg *message.Message) error {
128+
router.AddConsumerHandler("handler_name", "test", pubSub, func(msg *message.Message) error {
129129
return errors.New("error")
130130
})
131131

0 commit comments

Comments
 (0)