Skip to content

Conversation

kwasniew
Copy link
Contributor

@kwasniew kwasniew commented Aug 20, 2025

About the changes

Now that we released a new version of Java SDK with streaming support we can also add an example.

Run it with UNLEASH_API_TOKEN=sandbox_token UNLEASH_API_URL=sandbox_url ./gradlew run

The example listens to streaming changes and prints flag status and received events.

Most of the PR is boilerplate for gradle copied from other examples. Actual change is 60 LOC

Important files

Discussion points

}

dependencies {
implementation("io.getunleash:unleash-client-java:11.1.0")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version with streaming required


dependencies {
implementation("io.getunleash:unleash-client-java:11.1.0")
implementation("com.launchdarkly:okhttp-eventsource:4.1.1")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional dependency for streaming

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 17093964056

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 79.249%

Totals Coverage Status
Change from base Build 16902971413: 0.0%
Covered Lines: 2442
Relevant Lines: 3010

💛 - Coveralls

@gastonfournier gastonfournier moved this from New to In Progress in Issues and PRs Aug 21, 2025
@gastonfournier
Copy link
Contributor

gastonfournier commented Sep 5, 2025

I manually tested it against a server without streaming support, and it doesn't fall back to polling. I don't know if it's the intended behavior but it does use the backup to load the initial state but it does not fetch from upstream.

I double-checked, and it's not polling. I believe it should poll if streaming fails.

@gastonfournier
Copy link
Contributor

Against a server that supports streaming:

  1. If streaming is disabled from the client it works well with polling.
  2. If experimental mode streaming is disabled you can still have a streaming listener that will report (odd but not terrible)
  3. With experimental mode streaming enabled it works nicely.

The main difference with a server that doesn't support streaming is that the client will output:

[STREAMING ERROR] Streaming connection error

Which probably means the error is not handled (because disabling streaming works).

Copy link
Contributor

@gastonfournier gastonfournier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! The happy path works well. We know about this limitation #322 (comment) but it will be addressed later. Meanwhile, the features is clearly marked as experimental which means, it should not be used in production yet. Good step forward!

Comment on lines +48 to +56
System.out.println("Streaming client started. Waiting for events... (Press Ctrl+C to exit)");

try {
Thread.currentThread().join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
System.out.println("Streaming example shutting down");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok, I'd like to also get some feature evaluation result, but I tested that manually and it works well.

I did something similar to this:

while (true) {
unleash.isEnabled("advanced.constraints", context); // expect this to be true
unleash.isEnabled("advanced.constraints", smallerSemver); // expect this to be false
}
but limiting to 100 iterations with a sleep.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's boolean isEnabled = unleash.isEnabled("streaming_flag"); which is a flag you need to create and you will see it changing instantly on every streaming change. This is a similar pattern I did in Node SDK where we react to instant changes instead of looping which was fine for the polling mindset but for streaming event listening mindset seems to be more appropriate for me.

@github-project-automation github-project-automation bot moved this from In Progress to Approved PRs in Issues and PRs Sep 8, 2025
@kwasniew kwasniew merged commit 780b8ae into main Sep 9, 2025
27 of 30 checks passed
@kwasniew kwasniew deleted the streaming-example-cli branch September 9, 2025 07:21
@github-project-automation github-project-automation bot moved this from Approved PRs to Done in Issues and PRs Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants