Skip to content

Commit

Permalink
check multiple topics in one batch (#744)
Browse files Browse the repository at this point in the history
  • Loading branch information
maoruilei3120 committed Nov 30, 2021
1 parent a8b10ce commit 1b7e7e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ var (
ErrMessageEmpty = errors.New("message is nil")
ErrNotRunning = errors.New("producer not started")
ErrPullConsumer = errors.New("pull consumer has not supported")
ErrMultipleTopics = errors.New("the topic of the messages in one batch should be the same")
)
8 changes: 8 additions & 0 deletions producer/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ func (p *defaultProducer) checkMsg(msgs ...*primitive.Message) error {
if len(msgs[0].Topic) == 0 {
return errors2.ErrTopicEmpty
}

topic := msgs[0].Topic
for _, msg := range msgs {
if msg.Topic != topic {
return errors2.ErrMultipleTopics
}
}

return nil
}

Expand Down

0 comments on commit 1b7e7e5

Please sign in to comment.