Skip to content
New issue

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

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

Already on GitHub? # to your account

[Question] The best way to efficiently produce messages while ensuring their order #1319

Open
lcy0321 opened this issue Oct 21, 2024 · 0 comments

Comments

@lcy0321
Copy link

lcy0321 commented Oct 21, 2024

Hi Experts,

We are developing a service that requires the Kafka producer to support the following features:

  • At least once delivery, no message loss is acceptable
  • No re-ordering of messages
  • Retry as much as possible

I've read the INTRODUCTION.md of librdkafka and realize that the Idempotent Producer is close to our needs. However, there seems to be a very small chance that one or more messages in a queue could be lost due to a timeout. Is my understanding correct?

Currently, we are meeting these requirements by sending the messages synchronously, like this:

for {
    // Some retry logic here
    ...

    err := sendMessage(p, message)
    if err != nil {
        continue
    }
    break
}

func sendMessage(p *kafka.Producer, message *kafka.Message) error {
    deliveryChan := make(chan kafka.Event)
    err := p.Produce(message, deliveryChan)
    if err != nil {
        return err
    }
    e := <-deliveryChan
    // Check if the message was delivered; if not, return an error
    ...
    return nil
}

But producing messages one by one synchronously is heavily affecting the throughput.

Could you please provide recommendations for more efficient ways to meet these requirements?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant