Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable instant retry for non transactional retry mode #136

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions batch_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,14 @@ func (b *batchConsumer) process(chunkMessages []*Message) {
consumeErr := b.consumeFn(chunkMessages)

if consumeErr != nil {
b.logger.Warnf("Consume Function Err %s, Messages will be retried", consumeErr.Error())
// Try to process same messages again for resolving transient network errors etc.
if consumeErr = b.consumeFn(chunkMessages); consumeErr != nil {
b.logger.Warnf("Consume Function Again Err %s, messages are sending to exception/retry topic %s", consumeErr.Error(), b.retryTopic)
if b.transactionalRetry {
b.logger.Warnf("Consume Function Err %s, Messages will be retried", consumeErr.Error())
// Try to process same messages again for resolving transient network errors etc.
if consumeErr = b.consumeFn(chunkMessages); consumeErr != nil {
b.logger.Warnf("Consume Function Again Err %s, messages are sending to exception/retry topic %s", consumeErr.Error(), b.retryTopic)
b.metric.TotalUnprocessedMessagesCounter += int64(len(chunkMessages))
}
} else {
b.metric.TotalUnprocessedMessagesCounter += int64(len(chunkMessages))
}

Expand Down
12 changes: 8 additions & 4 deletions consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,14 @@ func (c *consumer) process(message *Message) {
consumeErr := c.consumeFn(message)

if consumeErr != nil {
c.logger.Warnf("Consume Function Err %s, Message will be retried", consumeErr.Error())
// Try to process same message again
if consumeErr = c.consumeFn(message); consumeErr != nil {
c.logger.Warnf("Consume Function Again Err %s, message is sending to exception/retry topic %s", consumeErr.Error(), c.retryTopic)
if c.transactionalRetry {
c.logger.Warnf("Consume Function Err %s, Message will be retried", consumeErr.Error())
// Try to process same message again
if consumeErr = c.consumeFn(message); consumeErr != nil {
c.logger.Warnf("Consume Function Again Err %s, message is sending to exception/retry topic %s", consumeErr.Error(), c.retryTopic)
c.metric.TotalUnprocessedMessagesCounter++
}
} else {
c.metric.TotalUnprocessedMessagesCounter++
}
}
Expand Down
4 changes: 2 additions & 2 deletions consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Test_consumer_process(t *testing.T) {
// Given
gotOnlyOneTimeException := true
c := consumer{
base: &base{metric: &ConsumerMetric{}, logger: NewZapLogger(LogLevelDebug)},
base: &base{metric: &ConsumerMetric{}, logger: NewZapLogger(LogLevelDebug), transactionalRetry: true},
consumeFn: func(*Message) error {
if gotOnlyOneTimeException {
gotOnlyOneTimeException = false
Expand All @@ -47,7 +47,7 @@ func Test_consumer_process(t *testing.T) {

// Then
if c.metric.TotalProcessedMessagesCounter != 1 {
t.Fatalf("Total Processed Message Counter must equal to 3")
t.Fatalf("Total Processed Message Counter must equal to 1")
}
if c.metric.TotalUnprocessedMessagesCounter != 0 {
t.Fatalf("Total Unprocessed Message Counter must equal to 0")
Expand Down
Loading