MCPcopy
hub / github.com/segmentio/kafka-go / readOffset

Function readOffset

writer_test.go:407–424  ·  writer_test.go::readOffset

readOffset gets the latest offset for the given topic/partition.

(topic string, partition int)

Source from the content-addressed store, hash-verified

405
406// readOffset gets the latest offset for the given topic/partition.
407func readOffset(topic string, partition int) (offset int64, err error) {
408 var conn *Conn
409
410 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
411 defer cancel()
412
413 if conn, err = DialLeader(ctx, "tcp", "localhost:9092", topic, partition); err != nil {
414 err = fmt.Errorf("readOffset, DialLeader: %w", err)
415 return
416 }
417 defer conn.Close()
418
419 offset, err = conn.ReadLastOffset()
420 if err != nil {
421 err = fmt.Errorf("readOffset, conn.ReadLastOffset: %w", err)
422 }
423 return
424}
425
426func readPartition(topic string, partition int, offset int64) (msgs []Message, err error) {
427 var conn *Conn

Callers 6

testWriterRoundRobin1Function · 0.85
testWriterBatchBytesFunction · 0.85
testWriterBatchSizeFunction · 0.85
testWriterMultipleTopicsFunction · 0.85

Calls 3

CloseMethod · 0.95
ReadLastOffsetMethod · 0.95
DialLeaderFunction · 0.85

Tested by

no test coverage detected