-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove StreamedFile mention * add ReferenceCounted * update callout number * change callout callout one line * rename guide to micronaut-reactor-streaming-http-client * add license
- Loading branch information
Showing
7 changed files
with
73 additions
and
109 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
...ut-reactor-streaming-http-client/java/src/main/java/example/micronaut/HomeController.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,69 @@ | ||
/* | ||
* Copyright 2017-2024 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package example.micronaut; | ||
|
||
import io.micronaut.context.exceptions.ConfigurationException; | ||
import io.micronaut.core.io.buffer.ByteBuffer; | ||
import io.micronaut.core.io.buffer.ReferenceCounted; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.annotation.Controller; | ||
import io.micronaut.http.annotation.Get; | ||
import io.micronaut.reactor.http.client.ReactorStreamingHttpClient; | ||
import jakarta.annotation.PreDestroy; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import reactor.core.publisher.Flux; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
import java.net.URL; | ||
|
||
@Controller // <1> | ||
class HomeController implements AutoCloseable { | ||
private static final Logger LOG = LoggerFactory.getLogger(HomeController.class); | ||
private static final URI DEFAULT_URI = URI.create("https://guides.micronaut.io/micronaut5K.png"); | ||
|
||
private final ReactorStreamingHttpClient reactorStreamingHttpClient; | ||
|
||
HomeController() { | ||
String urlStr = "https://guides.micronaut.io/"; | ||
URL url; | ||
try { | ||
url = new URL(urlStr); | ||
} catch (MalformedURLException e) { | ||
throw new ConfigurationException("malformed URL" + urlStr); | ||
} | ||
this.reactorStreamingHttpClient = ReactorStreamingHttpClient.create(url); // <2> | ||
} | ||
|
||
@Get // <3> | ||
Flux<ByteBuffer<?>> download() { | ||
HttpRequest<?> request = HttpRequest.GET(DEFAULT_URI); | ||
return reactorStreamingHttpClient.dataStream(request).doOnNext(bb -> { | ||
if (bb instanceof ReferenceCounted rc) { | ||
rc.retain(); | ||
} | ||
}); // <4> | ||
} | ||
|
||
@PreDestroy // <5> | ||
@Override | ||
public void close() { | ||
if (reactorStreamingHttpClient != null) { | ||
reactorStreamingHttpClient.close(); | ||
} | ||
} | ||
} |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...actor-streaming-http-client/metadata.json → ...actor-streaming-http-client/metadata.json
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
File renamed without changes
104 changes: 0 additions & 104 deletions
104
...nd-reactor-streaming-http-client/java/src/main/java/example/micronaut/HomeController.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/docs/common/callouts/callout-streaming-http-client-data-stream.adoc
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 |
---|---|---|
@@ -1 +1 @@ | ||
Request a stream of data where each emitted item is a `ByteBuffer` instance. | ||
The `dataStream` method emits instances of `ByteBuffer`. These instances are garbage collected after each chunk is emitted. In order to propagate the chunks to the response stream they need to be retained by calling the `retain()` method. The framework will call `release()` on these garbage collected chunks once each one is written to the response. |