Skip to content

Commit 6095dc4

Browse files
committed
don't use retries, include checkpoints
1 parent ac9c71a commit 6095dc4

2 files changed

Lines changed: 11 additions & 32 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ If you are using [Gradle] then add the following to your `build.gradle` file:
6060

6161
```groovy
6262
dependencies {
63-
implementation "com.authzed.api:authzed:v1.3.0"
63+
implementation "com.authzed.api:authzed:1.4.1"
6464
implementation 'io.grpc:grpc-api:1.72.0'
6565
implementation 'io.grpc:grpc-stub:1.72.0'
6666
}

examples/v1/CallingWatch.java

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import io.grpc.Status;
1111
import io.grpc.StatusRuntimeException;
1212
import java.util.Iterator;
13-
import java.util.List;
14-
import java.util.Map;
1513

1614
// Installation
1715
// https://search.maven.org/artifact/com.authzed.api/authzed
@@ -35,33 +33,14 @@ public static void main(String[] args) {
3533
ManagedChannel channel = ManagedChannelBuilder
3634
.forTarget(target)
3735
.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-
))
5836
.build();
5937

6038
ZedToken lastZedToken = ZedToken.newBuilder().setToken("").build();
6139

6240
while(true) {
6341
try {
6442
WatchRequest.Builder builder = WatchRequest.newBuilder();
43+
builder.addOptionalUpdateKinds(com.authzed.api.v1.WatchKind.WATCH_KIND_INCLUDE_CHECKPOINTS);
6544

6645
if (!lastZedToken.getToken().isEmpty()) {
6746
builder.setOptionalStartCursor(lastZedToken);
@@ -73,21 +52,21 @@ public static void main(String[] args) {
7352

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

7863
if (!msg.getChangesThrough().getToken().isEmpty()) {
7964
lastZedToken = msg.getChangesThrough();
8065
}
8166
}
82-
8367
} 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-
}
68+
System.out.println("Error calling watch: " + e.getMessage());
69+
return;
9170
}
9271
}
9372
}

0 commit comments

Comments
 (0)