Skip to content

Commit 7add8f9

Browse files
committed
don't use retries, include checkpoints
1 parent ac9c71a commit 7add8f9

File tree

1 file changed

+10
-29
lines changed

1 file changed

+10
-29
lines changed

examples/v1/CallingWatch.java

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,14 @@ public static void main(String[] args) {
3535
ManagedChannel channel = ManagedChannelBuilder
3636
.forTarget(target)
3737
.useTransportSecurity() // if not using TLS, replace with .usePlaintext()
38-
.disableServiceConfigLookUp()
39-
.defaultServiceConfig(Map.of(
40-
"methodConfig", List.of(
41-
Map.of(
42-
"name", List.of(
43-
Map.of(
44-
"service", "authzed.api.v1.WatchService",
45-
"method", "Watch"
46-
)
47-
),
48-
"retryPolicy", Map.of(
49-
"maxAttempts", "5",
50-
"initialBackoff", "1s",
51-
"backoffMultiplier", "4.0",
52-
"maxBackoff", "30s",
53-
"retryableStatusCodes", List.of("UNAVAILABLE", "INTERNAL")
54-
)
55-
)
56-
)
57-
))
5838
.build();
5939

6040
ZedToken lastZedToken = ZedToken.newBuilder().setToken("").build();
6141

6242
while(true) {
6343
try {
6444
WatchRequest.Builder builder = WatchRequest.newBuilder();
45+
builder.addOptionalUpdateKinds(com.authzed.api.v1.WatchKind.WATCH_KIND_INCLUDE_CHECKPOINTS);
6546

6647
if (!lastZedToken.getToken().isEmpty()) {
6748
builder.setOptionalStartCursor(lastZedToken);
@@ -73,21 +54,21 @@ public static void main(String[] args) {
7354

7455
while (watchStream.hasNext()) {
7556
WatchResponse msg = watchStream.next();
76-
System.out.println("Received watch response: " + msg);
57+
if (msg.getUpdatesCount() > 0) {
58+
for (var update : msg.getUpdatesList()) {
59+
System.out.println("Received update: " + update);
60+
}
61+
} else {
62+
System.out.println("No changes made in SpiceDB");
63+
}
7764

7865
if (!msg.getChangesThrough().getToken().isEmpty()) {
7966
lastZedToken = msg.getChangesThrough();
8067
}
8168
}
82-
8369
} catch (Exception e) {
84-
if (e instanceof StatusRuntimeException sre && (sre.getStatus().getCode().equals(Status.UNAVAILABLE.getCode()) ||
85-
sre.getStatus().getCode().equals(Status.INTERNAL.getCode()))) {
86-
// Stream probably got disconnected after inactivity. Retry
87-
} else {
88-
System.out.println("Error calling watch: " + e.getMessage());
89-
return;
90-
}
70+
System.out.println("Error calling watch: " + e.getMessage());
71+
return;
9172
}
9273
}
9374
}

0 commit comments

Comments
 (0)