# README
topic
- pure Go native client for YDB Topic
See ydb-go-sdk for describe all driver features.
YDB
is an open-source Distributed SQL Database that combines high availability and scalability with strict consistency and ACID transactions with CDC and Data stream features.
Installation
go get -u github.com/ydb-platform/ydb-go-sdk/v3
Example Usage
- connect to YDB
db, err := ydb.Open(ctx, "grpc://localhost:2136/local")
if err != nil {
log.Fatal(err)
}
- send messages
producerAndGroupID := "group-id"
writer, err := db.Topic().StartWriter(producerAndGroupID, "topicName",
topicoptions.WithMessageGroupID(producerAndGroupID),
topicoptions.WithCodec(topictypes.CodecGzip),
)
if err != nil {
log.Fatal(err)
}
data1 := []byte{1, 2, 3}
data2 := []byte{4, 5, 6}
mess1 := topicwriter.Message{Data: bytes.NewReader(data1)}
mess2 := topicwriter.Message{Data: bytes.NewReader(data2)}
err = writer.Write(ctx, mess1, mess2)
if err != nil {
log.Fatal(err)
}
- read messages
for {
msg, err := reader.ReadMessage(ctx)
if err != nil {
log.Fatal(err)
}
content, err := io.ReadAll(msg)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(content))
err = reader.Commit(msg.Context(), msg)
if err != nil {
log.Fatal(err)
}
}
# Packages
No description provided by the author
No description provided by the author
Package topicreader provide Reader to receive messages from YDB topics More examples in examples repository
https://github.com/ydb-platform/ydb-go-examples/tree/master/topic/topicreader.
No description provided by the author
No description provided by the author
No description provided by the author
# Interfaces
Client is interface for topic client Attention: the interface may be extended in the future.