Skip to content

Commit ad61489

Browse files
committed
add examples
1 parent d606c50 commit ad61489

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package topicoptions_test
2+
3+
import (
4+
"github.com/ydb-platform/ydb-go-sdk/v3"
5+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/topic"
6+
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topicoptions"
7+
)
8+
9+
func ExampleWithReaderCheckRetryErrorFunction() {
10+
var db ydb.Connection
11+
12+
reader, err := db.Topic().StartReader(
13+
"consumer",
14+
topicoptions.ReadTopic("topic"),
15+
topicoptions.WithReaderCheckRetryErrorFunction(
16+
func(errInfo topic.PublicCheckErrorRetryArgs) topic.PublicCheckRetryResult {
17+
// Retry not found operations
18+
if ydb.IsOperationErrorNotFoundError(errInfo.Error) {
19+
return topicoptions.CheckErrorRetryDecisionRetry
20+
}
21+
22+
// and use default behavior for all other errors
23+
return topicoptions.CheckErrorRetryDecisionDefault
24+
}),
25+
)
26+
_, _ = reader, err
27+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package topicoptions_test
2+
3+
import (
4+
"github.com/ydb-platform/ydb-go-sdk/v3"
5+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/topic"
6+
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topicoptions"
7+
)
8+
9+
func ExampleWithWriterCheckRetryErrorFunction() {
10+
var db ydb.Connection
11+
writer, err := db.Topic().StartWriter(
12+
"",
13+
"",
14+
topicoptions.WithWriterCheckRetryErrorFunction(
15+
func(errInfo topic.PublicCheckErrorRetryArgs) topic.PublicCheckRetryResult {
16+
// Retry for all transport errors
17+
if ydb.IsTransportError(errInfo.Error) {
18+
return topicoptions.CheckErrorRetryDecisionRetry
19+
}
20+
21+
// and use default behavior for all other errors
22+
return topicoptions.CheckErrorRetryDecisionDefault
23+
}),
24+
)
25+
_, _ = writer, err
26+
}

0 commit comments

Comments
 (0)