Skip to content

Commit d91922b

Browse files
authored
feat: update from fork
Feat/streamed list objects consumer
2 parents 7ba12cc + c19f755 commit d91922b

14 files changed

Lines changed: 1749 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.PHONY: build run run-openfga
2+
all: build
3+
4+
project_name=.
5+
openfga_version=latest
6+
language=java
7+
8+
build:
9+
./gradlew -P language=$(language) build
10+
11+
run:
12+
./gradlew -P language=$(language) run
13+
14+
run-openfga:
15+
docker pull docker.io/openfga/openfga:${openfga_version} && \
16+
docker run -p 8080:8080 docker.io/openfga/openfga:${openfga_version} run
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Streamed List Objects example for OpenFGA's Java SDK
2+
3+
This example demonstrates working with the `POST` `/stores/:id/streamed-list-objects` endpoint in OpenFGA using the Java SDK.
4+
5+
## Prerequisites
6+
7+
If you do not already have an OpenFGA instance running, you can start one using the following command:
8+
9+
```bash
10+
make run-openfga
11+
```
12+
13+
Or directly with docker:
14+
15+
```bash
16+
docker run -d -p 8080:8080 openfga/openfga run
17+
```
18+
19+
## Configure the example
20+
21+
You may need to configure the example for your environment by setting environment variables:
22+
23+
```bash
24+
export FGA_API_URL=http://localhost:8080
25+
```
26+
27+
Optional authentication configuration:
28+
```bash
29+
export FGA_CLIENT_ID=your-client-id
30+
export FGA_CLIENT_SECRET=your-client-secret
31+
export FGA_API_AUDIENCE=your-api-audience
32+
export FGA_API_TOKEN_ISSUER=your-token-issuer
33+
```
34+
35+
## Running the example
36+
37+
Build the project:
38+
39+
```bash
40+
make build
41+
```
42+
43+
Run the example:
44+
45+
```bash
46+
make run
47+
```
48+
49+
This will:
50+
1. Create a temporary store
51+
2. Create an authorization model
52+
3. Write 100 mock tuples
53+
4. Stream all objects using the `streamedListObjects` API
54+
5. Display each object as it's received
55+
6. Clean up the temporary store
56+
57+
## What to expect
58+
59+
The example will output each object as it's streamed from the server:
60+
61+
```
62+
Created temporary store (01HXXX...)
63+
Created temporary authorization model (01GXXX...)
64+
Writing 100 mock tuples to store.
65+
Listing objects using streaming endpoint:
66+
document:0
67+
document:1
68+
document:2
69+
...
70+
document:99
71+
API returned 100 objects.
72+
Deleted temporary store (01HXXX...)
73+
Finished.
74+
```
75+
76+
## Note
77+
78+
The streaming API is particularly useful when dealing with large result sets, as it:
79+
- Reduces memory usage by processing objects one at a time
80+
- Provides faster time-to-first-result
81+
- Allows for real-time processing of results
82+
- Is only limited by execution timeout rather than result set size
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
plugins {
2+
id 'application'
3+
id 'com.diffplug.spotless' version '8.0.0'
4+
}
5+
6+
application {
7+
mainClass = 'dev.openfga.sdk.example.StreamedListObjectsExample'
8+
}
9+
10+
repositories {
11+
mavenCentral()
12+
}
13+
14+
ext {
15+
jacksonVersion = "2.18.2"
16+
}
17+
18+
dependencies {
19+
// Use local build of SDK
20+
implementation files('../../build/libs/openfga-sdk-0.9.2.jar')
21+
22+
// Serialization
23+
implementation("com.fasterxml.jackson.core:jackson-core:$jacksonVersion")
24+
implementation("com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion")
25+
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
26+
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
27+
implementation("org.openapitools:jackson-databind-nullable:0.2.7")
28+
29+
// OpenTelemetry (required by SDK)
30+
implementation platform("io.opentelemetry:opentelemetry-bom:1.54.1")
31+
implementation "io.opentelemetry:opentelemetry-api"
32+
33+
// JSR305 (required by SDK)
34+
implementation "com.google.code.findbugs:jsr305:3.0.2"
35+
}
36+
37+
// Use spotless plugin to automatically format code, remove unused import, etc
38+
// To apply changes directly to the file, run `gradlew spotlessApply`
39+
// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle
40+
spotless {
41+
// comment out below to run spotless as part of the `check` task
42+
enforceCheck false
43+
format 'misc', {
44+
// define the files (e.g. '*.gradle', '*.md') to apply `misc` to
45+
target '.gitignore'
46+
// define the steps to apply to those files
47+
trimTrailingWhitespace()
48+
indentWithSpaces() // Takes an integer argument if you don't like 4
49+
endWithNewline()
50+
}
51+
java {
52+
palantirJavaFormat()
53+
removeUnusedImports()
54+
importOrder()
55+
}
56+
}
57+
58+
// Use spotless plugin to automatically format code, remove unused import, etc
59+
// To apply changes directly to the file, run `gradlew spotlessApply`
60+
// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle
61+
tasks.register('fmt') {
62+
dependsOn 'spotlessApply'
63+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language=java
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)