Skip to content

Commit

Permalink
rename EventConsumer => StartStopper
Browse files Browse the repository at this point in the history
This more accurately defines how the interface is used. That is, the consumers
of this interface are only interested in its lifecycle functionality, that is,
Start and Stop. The fact that the implementations happen to be event
consumers, is not in any way important to the consumers themselves.

This change will require changes to the consumers however, which includes (at
least) clinic-worker, platform, hydrophone, and marketo-service. The changes
required are just function argument renaming though, so very straightforward,
and could be done the next time they upgrade their go-common versions.
  • Loading branch information
ewollesen committed Mar 27, 2024
1 parent 2b9fbd9 commit 6d3b7b2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions events/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package events

import (
"context"
"log"

"github.com/Shopify/sarama"
"github.com/cloudevents/sdk-go/protocol/kafka_sarama/v2"
cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/cloudevents/sdk-go/v2/binding"
"log"
)

type EventConsumer interface {
// StartStopper provides lifecycle hooks for long-running service tasks.
type StartStopper interface {
Start() error
Stop() error
}
Expand Down
2 changes: 1 addition & 1 deletion events/consumer_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type SaramaEventConsumer struct {
cancelFunc context.CancelFunc
}

func NewSaramaConsumerGroup(config *CloudEventsConfig, consumer MessageConsumer) (EventConsumer, error) {
func NewSaramaConsumerGroup(config *CloudEventsConfig, consumer MessageConsumer) (*SaramaEventConsumer, error) {
if err := validateConsumerConfig(config); err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions events/fault_tolerant_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ type FaultTolerantConsumerGroup struct {
config *CloudEventsConfig
createConsumer ConsumerFactory
m sync.Mutex
delegate EventConsumer
delegate StartStopper
isShuttingDown bool
attempts uint
delay time.Duration
delayType retry.DelayTypeFunc
}

var _ EventConsumer = &FaultTolerantConsumerGroup{}
var _ StartStopper = &FaultTolerantConsumerGroup{}

func NewFaultTolerantConsumerGroup(config *CloudEventsConfig, createConsumer ConsumerFactory) (*FaultTolerantConsumerGroup, error) {
return &FaultTolerantConsumerGroup{
Expand Down

0 comments on commit 6d3b7b2

Please sign in to comment.