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

How can I get the latest message in a topic? #1240

Closed
cocoza4 opened this issue Nov 25, 2023 · 2 comments
Closed

How can I get the latest message in a topic? #1240

cocoza4 opened this issue Nov 25, 2023 · 2 comments
Assignees

Comments

@cocoza4
Copy link

cocoza4 commented Nov 25, 2023

No description provided.

@petedannemann
Copy link
Contributor

// make a new reader that consumes from topic-A, partition 0, at offset 42
r := kafka.NewReader(kafka.ReaderConfig{
    Brokers:   []string{"localhost:9092","localhost:9093", "localhost:9094"},
    Topic:     "topic-A",
    Partition: 0,
    MaxBytes:  10e6, // 10MB
})
r.SetOffset(kafka.LastOffset)

m, err := r.ReadMessage(context.Background())
if err != nil {
    log.Fatal("failed to read latest message:", err)
}

@petedannemann petedannemann self-assigned this Nov 29, 2023
@cocoza4
Copy link
Author

cocoza4 commented Nov 29, 2023

thank you

@cocoza4 cocoza4 closed this as completed Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants