Skip to content

Commit 4ea5cc1

Browse files
authored
Merge pull request #501 add examples for topic retry policy
2 parents 25f2de4 + 9e88b10 commit 4ea5cc1

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
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/topic/topicoptions"
6+
)
7+
8+
func ExampleWithReaderCheckRetryErrorFunction() {
9+
var db ydb.Connection
10+
11+
reader, err := db.Topic().StartReader(
12+
"consumer",
13+
topicoptions.ReadTopic("topic"),
14+
topicoptions.WithReaderCheckRetryErrorFunction(
15+
func(errInfo topicoptions.CheckErrorRetryArgs) topicoptions.CheckErrorRetryResult {
16+
// Retry not found operations
17+
if ydb.IsOperationErrorNotFoundError(errInfo.Error) {
18+
return topicoptions.CheckErrorRetryDecisionRetry
19+
}
20+
21+
// and use default behavior for all other errors
22+
return topicoptions.CheckErrorRetryDecisionDefault
23+
}),
24+
)
25+
_, _ = reader, err
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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/topic/topicoptions"
6+
)
7+
8+
func ExampleWithWriterCheckRetryErrorFunction() {
9+
var db ydb.Connection
10+
writer, err := db.Topic().StartWriter(
11+
"",
12+
"",
13+
topicoptions.WithWriterCheckRetryErrorFunction(
14+
func(errInfo topicoptions.CheckErrorRetryArgs) topicoptions.CheckErrorRetryResult {
15+
// Retry for all transport errors
16+
if ydb.IsTransportError(errInfo.Error) {
17+
return topicoptions.CheckErrorRetryDecisionRetry
18+
}
19+
20+
// and use default behavior for all other errors
21+
return topicoptions.CheckErrorRetryDecisionDefault
22+
}),
23+
)
24+
_, _ = writer, err
25+
}

0 commit comments

Comments
 (0)