github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/topic/topicreader/reader_example_test.go (about)

     1  package topicreader_test
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/ydb-platform/ydb-go-sdk/v3/topic/topicreader"
     7  )
     8  
     9  func ExampleReader_ReadMessage() {
    10  	ctx := context.TODO()
    11  	reader := readerConnect()
    12  
    13  	for {
    14  		msg, _ := reader.ReadMessage(ctx)
    15  		processMessage(msg.Context(), msg)
    16  		_ = reader.Commit(msg.Context(), msg)
    17  	}
    18  }
    19  
    20  func ExampleReader_Commit() {
    21  	ctx := context.TODO()
    22  	reader := readerConnect()
    23  
    24  	for {
    25  		batch, _ := reader.ReadMessageBatch(ctx)
    26  		processBatch(batch.Context(), batch)
    27  
    28  		// Commit may be fast (by default) or sync, depends on reader settings
    29  		_ = reader.Commit(batch.Context(), batch)
    30  	}
    31  }
    32  
    33  func ExampleReader_ReadMessageBatch() {
    34  	ctx := context.TODO()
    35  	reader := readerConnect()
    36  
    37  	for {
    38  		batch, _ := reader.ReadMessageBatch(ctx)
    39  		processBatch(batch.Context(), batch)
    40  		_ = reader.Commit(batch.Context(), batch)
    41  	}
    42  }
    43  
    44  func processBatch(ctx context.Context, batch *topicreader.Batch) {
    45  	// recommend derive ctx from batch.Context() for handle signal about stop message processing
    46  	panic("example stub")
    47  }
    48  
    49  func processMessage(ctx context.Context, m *topicreader.Message) {
    50  	// recommend derive ctx from m.Context() for handle signal about stop message processing
    51  	panic("example stub")
    52  }
    53  
    54  func readerConnect() *topicreader.Reader {
    55  	panic("example stub")
    56  }