Skip to content

Commit aa4762a

Browse files
committed
Sync documentation of main branch
1 parent da8ddb2 commit aa4762a

File tree

5 files changed

+93
-36
lines changed

5 files changed

+93
-36
lines changed

_versions/main/guides/dev-mode-differences.adoc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ Examples of such operations are:
4646
* Running scheduled operations
4747
* Building a container
4848

49-
[TIP]
50-
====
51-
A new Dev UI has been implemented in Quarkus 3.x.
52-
Not all the features are available yet.
53-
You can still access the previous version of the Dev UI using: http://localhost:8080/q/dev-ui/.
54-
====
55-
5649
=== Error pages
5750

5851
In an effort to make development errors very easy to diagnose, Quarkus provides various detailed error pages when running in dev mode.

_versions/main/guides/funqy-gcp-functions.adoc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ In this example, we will create two background functions and a cloud events func
8181
Background functions allow you to react to Google Cloud events like PubSub messages, Cloud Storage events, Firestore events, ...
8282
Cloud events functions allow you to react to supported events using the Cloud Events specification.
8383

84-
NOTE: Quarkus supports Cloud Functions gen 1 and gen 2. For an overview of Cloud Functions gen 2 see https://cloud.google.com/functions/docs/2nd-gen/overview[this page] on the Google Cloud Functions documentation. To use gen 2 you must add the `--gen2` parameter.
85-
8684
[source,java]
8785
----
8886
import jakarta.inject.Inject;
@@ -231,8 +229,6 @@ You can also simply add a file to Cloud Storage using the command line of the we
231229

232230
=== Cloud Events Functions - Cloud Storage
233231

234-
WARNING: Cloud Events Function is a feature of Cloud Functions gen 2 only.
235-
236232
Before deploying your function, you need to create a bucket.
237233

238234
[source,bash]
@@ -244,7 +240,7 @@ Then, use this command to deploy to Google Cloud Functions:
244240

245241
[source,bash]
246242
----
247-
gcloud functions deploy quarkus-example-cloud-event --gen2 \
243+
gcloud functions deploy quarkus-example-cloud-event \
248244
--entry-point=io.quarkus.funqy.gcp.functions.FunqyCloudEventsFunction \
249245
--runtime=java21 --trigger-bucket=example-cloud-event --source=target/deployment
250246
----
@@ -324,8 +320,6 @@ This will call your PubSub background function with a Cloud Storage event `{"nam
324320

325321
=== Cloud Events Functions - Cloud Storage
326322

327-
WARNING: Cloud Events Function is a feature of Cloud Functions gen 2 only.
328-
329323
For cloud events functions, you launch the invoker with a target class of `io.quarkus.funqy.gcp.functions.FunqyCloudEventsFunction``.
330324

331325
[source,bash,subs="attributes"]
@@ -457,8 +451,6 @@ class GreetingFunctionsStorageTest {
457451

458452
=== Cloud Events Functions - Cloud Storage
459453

460-
WARNING: Cloud Events Function is a feature of Cloud Functions gen 2 only.
461-
462454
[source,java]
463455
----
464456
import static io.restassured.RestAssured.given;

_versions/main/guides/gcp-functions-http.adoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ one for Reactive routes and one for xref:funqy-http.adoc[Funqy HTTP].
6363
[NOTE]
6464
====
6565
These various endpoints are for demonstration purposes.
66-
For real life applications, you should choose one of this technology and stick to it.
66+
For real life applications, you should choose one of these technologies and stick to it.
6767
====
6868

6969
If you don't need endpoints of each type, you can remove the corresponding extensions from your `pom.xml`.
7070

71-
NOTE: Quarkus supports Cloud Functions gen 1 and gen 2. For an overview of Cloud Functions gen 2 see https://cloud.google.com/functions/docs/2nd-gen/overview[this page] on the Google Cloud Functions documentation. To use gen 2 you must and add the `--gen2` parameter.
72-
7371
=== The Jakarta REST endpoint
7472

7573
[source,java]

_versions/main/guides/gcp-functions.adoc

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ gcloud auth login
5858
For this example project, we will create four functions, one `HttpFunction`, one `BackgroundFunction` (Storage event),
5959
one `RawBackgroundFunction` (PubSub event) and one `CloudEventsFunction` (storage event using the Cloud Events specification).
6060

61-
NOTE: Quarkus supports Cloud Functions gen 1 and gen 2. For an overview of Cloud Functions gen 2 see https://cloud.google.com/functions/docs/2nd-gen/overview[this page] on the Google Cloud Functions documentation. To use gen 2 you must add the `--gen2` parameter.
62-
6361
== Choose Your Function
6462

6563
The `quarkus-google-cloud-functions` extension scans your project for a class that directly implements the Google Cloud `HttpFunction`, `BackgroundFunction`, `RawBackgroundFunction` or `CloudEventsFunction` interface.
@@ -193,8 +191,6 @@ public class RawBackgroundFunctionPubSubTest implements RawBackgroundFunction {
193191

194192
=== The CloudEventsFunction
195193

196-
WARNING: `CloudEventsFunction` is a feature of Cloud Functions gen 2 only.
197-
198194
This `CloudEventsFunction` is triggered by a Cloud Events Storage event, you can use any Cloud Events supported by Google Cloud instead.
199195

200196
[source,java]
@@ -332,14 +328,12 @@ gcloud functions call quarkus-example-pubsub --data '{"data":{"greeting":"world"
332328

333329
=== The CloudEventsFunction
334330

335-
WARNING: `CloudEventsFunction` is a feature of Cloud Functions gen 2 only.
336-
337331
This is an example command to deploy your `CloudEventsFunction` to Google Cloud, as the function is triggered by a Storage event,
338332
it needs to use `--trigger-bucket` parameter with the name of a previously created bucket:
339333

340334
[source,bash]
341335
----
342-
gcloud functions deploy quarkus-example-cloud-event --gen2 \
336+
gcloud functions deploy quarkus-example-cloud-event \
343337
--entry-point=io.quarkus.gcp.functions.QuarkusCloudEventsFunction \
344338
--runtime=java21 --trigger-bucket=example-cloud-event --source=target/deployment
345339
----
@@ -429,8 +423,6 @@ This will call your PubSub background function with a PubSubMessage `{"greeting"
429423

430424
=== The CloudEventsFunction
431425

432-
IMPORTANT: `CloudEventsFunction` is a feature of Cloud Function gen 2 only.
433-
434426
For cloud events functions, you launch the invoker with a target class of `io.quarkus.gcp.functions.QuarkusCloudEventsFunction`.
435427

436428
[source,bash,subs="attributes"]
@@ -592,8 +584,6 @@ class RawBackgroundFunctionPubSubTestCase {
592584

593585
=== The CloudEventsFunction
594586

595-
WARNING: Cloud Events Function is a feature of Cloud Functions gen 2 only.
596-
597587
[source,java]
598588
----
599589
import static io.restassured.RestAssured.given;

_versions/main/guides/websockets-next-reference.adoc

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,29 @@ However, it may also accept the following parameters:
267267
The message object represents the data sent and can be accessed as either raw content (`String`, `JsonObject`, `JsonArray`, `Buffer` or `byte[]`) or deserialized high-level objects, which is the recommended approach.
268268

269269
When receiving a `Multi`, the method is invoked once per connection, and the provided `Multi` receives the items transmitted by this connection.
270-
The method must subscribe to the `Multi` to receive these items (or return a Multi).
270+
If the method returns a `Multi` (constructed from the received one), Quarkus will automatically subscribe to it and write the emitted items until completion, failure, or cancellation.
271+
However, if your method does not return a `Multi`, you must subscribe to the incoming `Multi` to consume the data.
272+
273+
Here are two examples:
274+
275+
[source,java]
276+
----
277+
// No need to subscribe to the incoming Multi as the method returns a Multi derived from the incoming one
278+
@OnTextMessage
279+
public Multi<ChatMessage> stream(Multi<ChatMessage> incoming) {
280+
return incoming.log();
281+
}
282+
283+
// ...
284+
285+
// Must subscribe to the incoming Multi as the method does not return a Multi, otherwise no data will be consumed
286+
@OnTextMessage
287+
public void stream(Multi<ChatMessage> incoming) {
288+
incoming.subscribe().with(item -> log(item));
289+
}
290+
----
291+
292+
See <<subscribe-or-not-subscribe>> to learn more about subscribing to the incoming `Multi`.
271293

272294
==== Supported return types
273295

@@ -319,7 +341,9 @@ Multi<ResponseMessage> stream(Message m) {
319341
}
320342
----
321343

322-
When returning a Multi, Quarkus subscribes to the returned Multi automatically and writes the emitted items until completion, failure, or cancellation. Failure or cancellation terminates the connection.
344+
Methods returning `Uni` and `Multi` are considered non-blocking.
345+
In addition, Quarkus automatically subscribes to the returned `Multi` / `Uni` and writes the emitted items until completion, failure, or cancellation.
346+
Failure or cancellation terminates the connection.
323347

324348
==== Streams
325349

@@ -340,7 +364,8 @@ public Multi<ChatMessage> stream(Multi<ChatMessage> incoming) {
340364

341365
This approach allows bi-directional streaming.
342366

343-
When the method returns `void`, it must subscribe to the incoming `Multi`:
367+
When the method returns `void`, and so does not return a `Multi`, the code must subscribe to the incoming `Multi`.
368+
Otherwise, no data will be consumed, and the connection will not be closed:
344369

345370
[source, java]
346371
----
@@ -350,6 +375,10 @@ public void stream(Multi<ChatMessage> incoming) {
350375
}
351376
----
352377

378+
Also note that the `stream` method will complete before the `Multi` completes.
379+
380+
See <<subscribe-or-not-subscribe>> to learn more about subscribing to the incoming `Multi`.
381+
353382
==== Skipping reply
354383

355384
When a method is intended to produce a message written to the client, it can emit `null`.
@@ -636,7 +665,19 @@ String param = connection.pathParam("foo");
636665
The `WebSocketConnection` provides both a blocking and a non-blocking method variants to send messages:
637666

638667
- `sendTextAndAwait(String message)`: Sends a text message to the client and waits for the message to be sent. It's blocking and should only be called from an executor thread.
639-
- `sendText(String message)`: Sends a text message to the client. It returns a `Uni`. It's non-blocking, but you must subscribe to it.
668+
- `sendText(String message)`: Sends a text message to the client. It returns a `Uni`. It's non-blocking. Make sure you or Quarkus subscribes to the returned `Uni` to send the message.
669+
If you return the `Uni` from a method invoked by Quarkus (like with Quarkus REST, Quarkus WebSocket Next or Quarkus Messaging), it will subscribe to it and send the message.
670+
For example:
671+
672+
[source,java]
673+
----
674+
@POST
675+
public Uni<Void> send() {
676+
return connection.sendText("Hello!"); // Quarkus automatically subscribes to the returned Uni and sends the message.
677+
}
678+
----
679+
680+
See <<subscribe-or-not-subscribe>> to learn more about subscribing to the `Uni`.
640681

641682
[[list-open-connections]]
642683
==== List open connections
@@ -655,7 +696,7 @@ class MyBean {
655696
OpenConnections connections;
656697
657698
void logAllOpenConnections() {
658-
Log.infof("Open connections: %s", connections.listAll()); <1>
699+
Log.infof("Open connections: %s", connections.listAll()); // <1>
659700
}
660701
}
661702
----
@@ -1078,7 +1119,17 @@ String param = connection.pathParam("foo");
10781119
The `WebSocketClientConnection` provides both a blocking and a non-blocking method variants to send messages:
10791120

10801121
- `sendTextAndAwait(String message)`: Sends a text message to the client and waits for the message to be sent. It's blocking and should only be called from an executor thread.
1081-
- `sendText(String message)`: Sends a text message to the client. It returns a `Uni`. It's non-blocking, but you must subscribe to it.
1122+
- `sendText(String message)`: Sends a text message to the client. It returns a `Uni`. It's non-blocking. Make sure you or Quarkus subscribes to the returned `Uni` to send the message.
1123+
If you return the `Uni` from a method invoked by Quarkus (like with Quarkus REST, Quarkus WebSocket Next or Quarkus Messaging), it will subscribe to it and send the message.
1124+
For example:
1125+
1126+
[source,java]
1127+
----
1128+
@POST
1129+
public Uni<Void> send() {
1130+
return connection.sendText("Hello!"); // Quarkus automatically subscribes to the returned Uni and sends the message.
1131+
}
1132+
----
10821133

10831134
[[list-open-client-connections]]
10841135
==== List open client connections
@@ -1203,6 +1254,39 @@ quarkus.log.category."io.quarkus.websockets.next.traffic".level=DEBUG <3>
12031254
<2> Set the number of characters of a text message payload which will be logged.
12041255
<3> Enable `DEBUG` level is for the logger `io.quarkus.websockets.next.traffic`.
12051256

1257+
[[subscribe-or-not-subscribe]]
1258+
== When to subscribe to a `Uni` or `Multi`
1259+
1260+
`Uni` and `Multi` are lazy types, which means that they do not start processing until they are subscribed to.
1261+
1262+
When you get (from a parameter or from a method you called) a `Uni` or a `Multi`, whether you should subscribe to it depends on the context:
1263+
1264+
- if you return the `Uni` or `Multi` in a method invoked by Quarkus (like with Quarkus REST, Quarkus WebSocket Next or Quarkus Messaging), Quarkus subscribes to it and processes the items emitted by the `Multi` or the item emitted by the `Uni`:
1265+
1266+
[source, java]
1267+
----
1268+
@Incoming("...")
1269+
@Outgoing("...")
1270+
public Multi<String> process(Multi<String> input) {
1271+
// No need to subscribe to the input Multi, the `process` method is called by Quarkus (Messaging).
1272+
return input.map(String::toUpperCase);
1273+
}
1274+
----
1275+
1276+
When a `Uni` or `Multi` is returned from a method annotated with `@OnOpen`, `@OnTextMessage`, `@OnBinaryMessage`, or `@OnClose`, Quarkus subscribes to it automatically.
1277+
1278+
- if you do not return the `Uni` or `Multi` in a method invoked by Quarkus, you should subscribe to it:
1279+
1280+
[source, java]
1281+
----
1282+
@Incoming("...")
1283+
@Outgoing("...")
1284+
public void process(Multi<String> input) {
1285+
input.map(String::toUpperCase)
1286+
.subscribe().with(s -> log(s));
1287+
}
1288+
----
1289+
12061290
[[telemetry]]
12071291
== Telemetry
12081292

0 commit comments

Comments
 (0)