Skip to content

Commit f239482

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

2 files changed

Lines changed: 15 additions & 49 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: 14 additions & 48 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,60 +33,28 @@ 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

60-
ZedToken lastZedToken = ZedToken.newBuilder().setToken("").build();
38+
try {
39+
WatchRequest request = WatchRequest.
40+
newBuilder()
41+
.addOptionalUpdateKinds(com.authzed.api.v1.WatchKind.WATCH_KIND_INCLUDE_CHECKPOINTS)
42+
.build();
6143

62-
while(true) {
63-
try {
64-
WatchRequest.Builder builder = WatchRequest.newBuilder();
44+
Iterator<WatchResponse> watchStream = watchClient.watch(request);
6545

66-
if (!lastZedToken.getToken().isEmpty()) {
67-
builder.setOptionalStartCursor(lastZedToken);
68-
}
69-
70-
WatchRequest request = builder.build();
71-
72-
Iterator<WatchResponse> watchStream = watchClient.watch(request);
73-
74-
while (watchStream.hasNext()) {
75-
WatchResponse msg = watchStream.next();
76-
System.out.println("Received watch response: " + msg);
77-
78-
if (!msg.getChangesThrough().getToken().isEmpty()) {
79-
lastZedToken = msg.getChangesThrough();
46+
while (watchStream.hasNext()) {
47+
WatchResponse msg = watchStream.next();
48+
if (msg.getUpdatesCount() > 0) {
49+
for (var update : msg.getUpdatesList()) {
50+
System.out.println("Received update: " + update);
8051
}
81-
}
82-
83-
} 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
8752
} else {
88-
System.out.println("Error calling watch: " + e.getMessage());
89-
return;
53+
System.out.println("No changes made in SpiceDB");
9054
}
9155
}
56+
} catch (Exception e) {
57+
System.out.println("Error calling watch: " + e.getMessage());
9258
}
9359
}
9460
}

0 commit comments

Comments
 (0)