/
githubmirror
/
ydb-go-sdk
Обзор
Документация
Войти
/
githubmirror
/
ydb-go-sdk
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/topic/topicreader/topicreader_show.go
30 строк
995 B
Timofey Koolin
fix linter warnings
01 авг 2024, 21:39
01 авг 2024, 21:39
defe086
Код
Авторство
О чём код?
package topicreaderexamples import ( "context" "github.com/ydb-platform/ydb-go-sdk/v3" "github.com/ydb-platform/ydb-go-sdk/v3/topic/topicreader" ) // PartitionStopHandled is example of sdk handle server signal about stop partition func PartitionStopHandled(ctx context.Context, reader *topicreader.Reader) { batch, _ := reader.ReadMessagesBatch(ctx) if len(batch.Messages) == 0 { return } batchContext := batch.Context() // batch.Context() will cancel when partition revoke by server or connection broke _, _ = processBatch(batchContext, batch) } // PartitionGracefulStopHandled is example of sdk handle server signal about graceful stop partition func PartitionGracefulStopHandled(ctx context.Context, db *ydb.Driver) { reader, _ := db.Topic().StartReader("consumer", nil) for { batch, _ := reader.ReadMessagesBatch(ctx) // <- if partition soft stop batch can be less, then 1000 _, _ = processBatch(batch.Context(), batch) _ = reader.Commit(batch.Context(), batch) } }