-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance RestMulti, configurable demand + distinct objects
Adds two enhancements: 1. Produce multiple JSON objects, not just an array 2. Make requested demand configurable == Produce multiple JSON objects Currently, `PublisherResponseHandler.StreamingMultiSubscriber` produces a JSON array, where each emitted item is encoded as a JSON array element. For some use cases it is easier to consume a bunch of "bare" JSON objects - i.e. just write the individual JSON objects, possibly separated by a newline. As an option, of course. Proposal to add: ```java RestMulti.fromMultiData(multi).encodeAsArray(false)... ``` With `encodeAsArray(false)`, the produced JSON would look like this: ```json {"some": "value"} {"some": "value"} {"some": "value"} ``` `encodeAsArray(true)` or omitting it would use the current behavior and produce something like this: ```json [{"some": "value"}, {"some": "value"}, {"some": "value"} } ``` == Configure request-demand All implementations of `PublisherResponseHandler.AbstractMultiSubscriber` work with a hard-coded request-demand of `1`, which means that every emitted item is "produced"/"computed" serially / one-after-the-other. If the computation of individual items takes somewhat longer, possibly waiting for remote resources to reply, it makes sense to use a higher demand to produce multiple items concurrently. For example, if each item takes maybe 250 ms (requesting data from a remote source) to be produced, and 100 items are produced, it currently takes 25 seconds. With a higher concurrency it would take a fraction of that time. I.e. if the use case is known to be not CPU but (async) I/O bound, it _might_ be legit/feasible to use a high demand. Proposal to add: ``` RestMulti.fromMultiData(multi).withDemand( (long) 123 )... ``` Which would pass `123` as the demand for all call sites to `Subscription.request` in implementations of `PublisherResponseHandler.AbstractMultiSubscriber`.
- Loading branch information
Showing
6 changed files
with
374 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...t/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/streams/Demands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.quarkus.resteasy.reactive.jackson.deployment.test.streams; | ||
|
||
import java.util.List; | ||
|
||
public class Demands { | ||
public List<Long> demands; | ||
|
||
public Demands(List<Long> demands) { | ||
this.demands = demands; | ||
} | ||
|
||
// for Jsonb | ||
public Demands() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.