Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON streaming for RESTEasy Reactive Jsonb and Jackson #20908

Merged
merged 2 commits into from
Jan 21, 2022

Conversation

Sgitario
Copy link
Contributor

@Sgitario Sgitario commented Oct 20, 2021

We now support json streaming. Example:

    @Path("stream-json/multi")
    @GET
    @Produces(SseMediaType.APPLICATION_STREAM_JSON)
    @RestSseElementType(MediaType.APPLICATION_JSON)
    public Multi<Message> multiStreamJson() {
        return Multi.createFrom().items(new Message("hello"), new Message("stef"));
    }

We support "application/x-ndjson" and "application/stream+json".

Moreover, I've added a new utility class called SseMediaType to be used by users. The implementation is similar to MediaType.

Questions:

  • Added for both JSONB and Jackson extensions, is this correct?
  • I've copied the existing tests we had for sse in JSONB to Jackson, is this correct?

Fix #13663

@geoand
Copy link
Contributor

geoand commented Oct 20, 2021

Glad to see this, thanks!

@FroMage is the expert on streaming, so let's get a review from him :)

@geoand geoand requested a review from FroMage October 20, 2021 13:53
@@ -197,24 +242,40 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti
// media type negotiation and fixed entity writer set up, perhaps it's better than
// cancelling the normal route?
// or make this SSE produce build-time
MediaType[] mediaTypes = requestContext.getTarget().getProduces().getSortedMediaTypes();
if (mediaTypes.length != 1)
MediaType[] mediaTypes = requestContext.getTarget().getProduces().getSortedOriginalMediaTypes();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to use getSortedOriginalMediaTypes because when using application/stream+json, we were only getting application/json using the method getSortedMediaTypes.

@quarkus-bot
Copy link

quarkus-bot bot commented Oct 20, 2021

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building 1e32c23

Status Name Step Failures Logs Raw logs
Initial JDK 11 Build Build Failures Logs Raw logs

Failures

⚙️ Initial JDK 11 Build #

- Failing: independent-projects/resteasy-reactive/server/runtime 
! Skipped: devtools/bom-descriptor-json docs extensions/agroal/deployment and 210 more

📦 independent-projects/resteasy-reactive/server/runtime

Failed to execute goal net.revelc.code:impsort-maven-plugin:1.6.2:check (check-imports) on project resteasy-reactive: Imports are not sorted in /home/runner/work/quarkus/quarkus/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java

@geoand
Copy link
Contributor

geoand commented Oct 20, 2021

PR needs formatting

@Sgitario
Copy link
Contributor Author

PR needs formatting

It should be fixed now

@Sgitario
Copy link
Contributor Author

Sgitario commented Nov 5, 2021

PR updated to resolve some new conflicts with main.

@quarkus-bot
Copy link

quarkus-bot bot commented Nov 5, 2021

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building eb1994f

Status Name Step Failures Logs Raw logs
Native Tests - Windows - hibernate-validator Build Failures Logs Raw logs

Failures

⚙️ Native Tests - Windows - hibernate-validator #

- Failing: integration-tests/hibernate-validator 

📦 integration-tests/hibernate-validator

Failed to execute goal io.quarkus:quarkus-maven-plugin:999-SNAPSHOT:build (default) on project quarkus-integration-test-hibernate-validator: Failed to build quarkus application

@geoand
Copy link
Contributor

geoand commented Nov 29, 2021

This now needs a rebase

@Sgitario
Copy link
Contributor Author

This now needs a rebase

Done

@geoand
Copy link
Contributor

geoand commented Nov 29, 2021

@FroMage can you take a look at this one?

@gsmet
Copy link
Member

gsmet commented Jan 12, 2022

@geoand what should we do with this one?

@geoand
Copy link
Contributor

geoand commented Jan 12, 2022

Ping @FroMage again 😊

Copy link
Member

@FroMage FroMage 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, except a few comments, and requires a mention in the documentation, linking to the stream specs.

@FroMage
Copy link
Member

FroMage commented Jan 18, 2022

Really sorry about the late review, this completely slipped past me.

@Sgitario
Copy link
Contributor Author

@FroMage PR updated with one of your suggestions

Copy link
Member

@FroMage FroMage left a comment

Choose a reason for hiding this comment

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

Looks great, just the question of the supertype of RestMediaType left.

@quarkus-bot
Copy link

quarkus-bot bot commented Jan 20, 2022

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building 0c102bf

Status Name Step Failures Logs Raw logs
Gradle Tests - JDK 11 Windows Build Failures Logs Raw logs

Full information is available in the Build summary check run.

Failures

⚙️ Gradle Tests - JDK 11 Windows #

- Failing: integration-tests/gradle 

📦 integration-tests/gradle

io.quarkus.gradle.devmode.MultiModuleKotlinProjectDevModeTest.main line 22 - More details - Source on GitHub

org.awaitility.core.ConditionTimeoutException: Condition with lambda expression in io.quarkus.test.devmode.util.DevModeTestUtils that uses java.util.function.Supplier, java.util.function.Supplierjava.util.concurrent.atomic.AtomicReference was not fulfilled within 3 minutes.
	at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:164)
	at org.awaitility.core.CallableCondition.await(CallableCondition.java:78)

@quarkus-bot
Copy link

quarkus-bot bot commented Jan 20, 2022

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building f154712

Status Name Step Failures Logs Raw logs
Initial JDK 11 Build Build Failures Logs Raw logs

Failures

⚙️ Initial JDK 11 Build #

- Failing: extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment 
! Skipped: docs extensions/apicurio-registry-avro/deployment extensions/avro/deployment and 77 more

📦 extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project quarkus-resteasy-reactive-deployment: Compilation failure /home/runner/work/quarkus/quarkus/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/QuarkusServerEndpointIndexer.java:[185,95] cannot find symbol symbol: method getSseElementType() location: variable method of type org.jboss.resteasy.reactive.server.model.ServerResourceMethod

@quarkus-bot
Copy link

quarkus-bot bot commented Jan 20, 2022

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building 9f1823d

Status Name Step Failures Logs Raw logs
Gradle Tests - JDK 11 Windows Build Failures Logs Raw logs

Full information is available in the Build summary check run.

Failures

⚙️ Gradle Tests - JDK 11 Windows #

- Failing: integration-tests/gradle 

📦 integration-tests/gradle

io.quarkus.gradle.devmode.MultiModuleKotlinProjectDevModeTest.main line 22 - More details - Source on GitHub

org.awaitility.core.ConditionTimeoutException: Condition with lambda expression in io.quarkus.test.devmode.util.DevModeTestUtils that uses java.util.function.Supplier, java.util.function.Supplierjava.util.concurrent.atomic.AtomicReference was not fulfilled within 3 minutes.
	at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:164)
	at org.awaitility.core.CallableCondition.await(CallableCondition.java:78)

io.quarkus.gradle.devmode.QuarkusDevDependencyDevModeTest.main line 14 - More details - Source on GitHub

org.awaitility.core.ConditionTimeoutException: Condition with lambda expression in io.quarkus.test.devmode.util.DevModeTestUtils that uses java.util.function.Supplier, java.util.function.Supplierjava.util.concurrent.atomic.AtomicReference, java.util.concurrent.atomic.AtomicReferencejava.lang.String, java.lang.Stringboolean was not fulfilled within 1 minutes.
	at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:164)
	at org.awaitility.core.CallableCondition.await(CallableCondition.java:78)

We now support json streaming. Example:

```
@path("stream-json/multi")
    @get
    @produces(SseMediaType.APPLICATION_STREAM_JSON)
    @RestSseElementType(MediaType.APPLICATION_JSON)
    public Multi<Message> multiStreamJson() {
        return Multi.createFrom().items(new Message("hello"), new Message("stef"));
    }
```

We support "application/x-ndjson" and "application/stream+json".

Moreover, I've added a new utility class called `SseMediaType` to be used by users. The implementation is similar to `MediaType`.
@quarkus-bot
Copy link

quarkus-bot bot commented Jan 21, 2022

Failing Jobs - Building d684ebe

Status Name Step Failures Logs Raw logs
Gradle Tests - JDK 11 Windows Build Failures Logs Raw logs

Full information is available in the Build summary check run.

Failures

⚙️ Gradle Tests - JDK 11 Windows #

- Failing: integration-tests/gradle 

📦 integration-tests/gradle

io.quarkus.gradle.devmode.InjectQuarkusAppPropertiesDevModeTest.main line 19 - More details - Source on GitHub

org.awaitility.core.ConditionTimeoutException: Condition with lambda expression in io.quarkus.test.devmode.util.DevModeTestUtils that uses java.util.function.Supplier, java.util.function.Supplierjava.util.concurrent.atomic.AtomicReference, java.util.concurrent.atomic.AtomicReferencejava.lang.String, java.lang.Stringboolean was not fulfilled within 1 minutes.
	at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:164)
	at org.awaitility.core.CallableCondition.await(CallableCondition.java:78)

Copy link
Member

@FroMage FroMage left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@FroMage FroMage merged commit 6ed8eb2 into quarkusio:main Jan 21, 2022
@quarkus-bot quarkus-bot bot added this to the 2.8 - main milestone Jan 21, 2022
@FroMage
Copy link
Member

FroMage commented Jan 21, 2022

CI failure unrelated: merging

@Sgitario Sgitario deleted the add_stream_json branch January 22, 2022 07:11
Sgitario added a commit to Sgitario/quarkus that referenced this pull request Mar 9, 2022
We're wrongly using `/n` instead of `\n`.
This was done in quarkusio#20908
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RESTEasy Reactive: investigate JSON streaming
4 participants