You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _versions/main/guides/funqy-gcp-functions.adoc
+1-9Lines changed: 1 addition & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,8 +81,6 @@ In this example, we will create two background functions and a cloud events func
81
81
Background functions allow you to react to Google Cloud events like PubSub messages, Cloud Storage events, Firestore events, ...
82
82
Cloud events functions allow you to react to supported events using the Cloud Events specification.
83
83
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
-
86
84
[source,java]
87
85
----
88
86
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
231
229
232
230
=== Cloud Events Functions - Cloud Storage
233
231
234
-
WARNING: Cloud Events Function is a feature of Cloud Functions gen 2 only.
235
-
236
232
Before deploying your function, you need to create a bucket.
237
233
238
234
[source,bash]
@@ -244,7 +240,7 @@ Then, use this command to deploy to Google Cloud Functions:
Copy file name to clipboardExpand all lines: _versions/main/guides/gcp-functions-http.adoc
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,13 +63,11 @@ one for Reactive routes and one for xref:funqy-http.adoc[Funqy HTTP].
63
63
[NOTE]
64
64
====
65
65
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.
67
67
====
68
68
69
69
If you don't need endpoints of each type, you can remove the corresponding extensions from your `pom.xml`.
70
70
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.
Copy file name to clipboardExpand all lines: _versions/main/guides/gcp-functions.adoc
+1-11Lines changed: 1 addition & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,8 +58,6 @@ gcloud auth login
58
58
For this example project, we will create four functions, one `HttpFunction`, one `BackgroundFunction` (Storage event),
59
59
one `RawBackgroundFunction` (PubSub event) and one `CloudEventsFunction` (storage event using the Cloud Events specification).
60
60
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
-
63
61
== Choose Your Function
64
62
65
63
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 {
193
191
194
192
=== The CloudEventsFunction
195
193
196
-
WARNING: `CloudEventsFunction` is a feature of Cloud Functions gen 2 only.
197
-
198
194
This `CloudEventsFunction` is triggered by a Cloud Events Storage event, you can use any Cloud Events supported by Google Cloud instead.
Copy file name to clipboardExpand all lines: _versions/main/guides/websockets-next-reference.adoc
+90-6Lines changed: 90 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -267,7 +267,29 @@ However, it may also accept the following parameters:
267
267
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.
268
268
269
269
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`.
271
293
272
294
==== Supported return types
273
295
@@ -319,7 +341,9 @@ Multi<ResponseMessage> stream(Message m) {
319
341
}
320
342
----
321
343
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.
323
347
324
348
==== Streams
325
349
@@ -340,7 +364,8 @@ public Multi<ChatMessage> stream(Multi<ChatMessage> incoming) {
340
364
341
365
This approach allows bi-directional streaming.
342
366
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:
344
369
345
370
[source, java]
346
371
----
@@ -350,6 +375,10 @@ public void stream(Multi<ChatMessage> incoming) {
350
375
}
351
376
----
352
377
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
+
353
382
==== Skipping reply
354
383
355
384
When a method is intended to produce a message written to the client, it can emit `null`.
The `WebSocketConnection` provides both a blocking and a non-blocking method variants to send messages:
637
666
638
667
- `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`.
The `WebSocketClientConnection` provides both a blocking and a non-blocking method variants to send messages:
1079
1120
1080
1121
- `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.
<2> Set the number of characters of a text message payload which will be logged.
1204
1255
<3> Enable `DEBUG` level is for the logger `io.quarkus.websockets.next.traffic`.
1205
1256
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:
0 commit comments