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: _guides/command-mode-reference.adoc
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -248,7 +248,17 @@ public class HelloIT extends HelloTest {
248
248
}
249
249
----
250
250
251
-
=== Mocking
251
+
=== Limitations
252
+
253
+
`@QuarkusMainTest` does **not** support the following features:
254
+
255
+
- Injection of CDI beans
256
+
- Using Panache entities
257
+
- Using mocks with `@InjectMock`
258
+
259
+
Usually, it's best to use a combination of `@QuarkusMainTest` tests for testing application externals, and `@QuarkusTest` tests for fine-grained testing which requires access to application internals.
260
+
261
+
==== Mocking
252
262
253
263
CDI injection is not supported in the `@QuarkusMainTest` tests.
254
264
Consequently, mocking CDI beans with `QuarkusMock` or `@InjectMock` is not supported either.
IMPORTANT: The content of this guide has been revised and split into additional topics. Please check the <<additional-information,Additional Information>> section.
16
-
17
15
In this reference guide we're going to describe various aspects of Quarkus configuration. A Quarkus application and
18
16
Quarkus itself (core and extensions) are both configured via the same mechanism that leverages
19
17
the https://github.com/smallrye/smallrye-config[SmallRye Config] API an implementation of the
@@ -195,9 +193,80 @@ Quarkus provides additional extensions which cover other configuration formats a
195
193
196
194
TIP: It is also possible to create a xref:config-extending-support.adoc#custom-config-source[Custom Config Source].
197
195
198
-
== Inject
196
+
== ConfigMapping
197
+
198
+
The recommended way to expose configuration to a Quarkus application is by mapping it with an interface. With
199
+
https://smallrye.io/smallrye-config/Main/config/mappings/[SmallRye Config Mappings], it is possible to
200
+
group multiple configuration properties in a single interface that share the same prefix (or namespace). It supports
201
+
the following set of features:
202
+
203
+
* Automatic conversion of the configuration type, including List, Set, Map, Optional, and primitive types.
204
+
* Nested Config Mapping groups.
205
+
* Configuration Properties Naming Strategies
206
+
* Integration with Bean Validation
199
207
200
-
Quarkus uses https://microprofile.io/project/eclipse/microprofile-config[MicroProfile Config] annotations to inject the
208
+
A Config Mapping requires an interface with minimal metadata configuration annotated with
209
+
`@io.smallrye.config.ConfigMapping`:
210
+
211
+
[source,java]
212
+
----
213
+
@ConfigMapping(prefix = "server")
214
+
public interface Server {
215
+
String host();
216
+
217
+
int port();
218
+
219
+
int sslPort();
220
+
}
221
+
----
222
+
223
+
A complex object type uses the following rules to map configuration values to their member values:
224
+
225
+
* A configuration path is built by taking the object type prefix (or namespace) and the mapping member name
226
+
* The member name is converted to its kebab-case format
227
+
* If the member name is represented as a getter, the member name is taken from its property name equivalent, and then
228
+
converted to its kebab-case format.
229
+
* The configuration value is automatically converted to the member type
230
+
* The configuration path is required to exist with a valid configuration value or the mapping will fail.
231
+
232
+
NOTE: Kebab-case - the method name is derived by replacing case changes with a dash to map the configuration property.
233
+
234
+
The `Server` interface can map configuration properties with the name `server.host` into the `Server.host()`
235
+
method, `server.port` into `Server.port()` method, and `server.ssl-port` into `Server.sslPort()` method. The
236
+
configuration property name to look up is constructed from the prefix and the method name (in kebab-case), separated
237
+
by adot (`.`) character.
238
+
239
+
A `@ConfigMapping` can be injected into any CDI aware bean:
240
+
241
+
[source,java]
242
+
----
243
+
@ApplicationScoped
244
+
class BusinessBean {
245
+
@Inject
246
+
Server server;
247
+
248
+
void businessMethod() {
249
+
String host = server.host();
250
+
}
251
+
}
252
+
----
253
+
254
+
For non-CDI components, use the `io.smallrye.config.SmallRyeConfig#getConfigMapping` API to retrieve the config mapping
Server server = config.getConfigMapping(Server.class);
261
+
----
262
+
263
+
TIP: Check the xref:config-mappings.adoc[Mapping configuration to objects] guide for advanced usages with
264
+
`@ConfigMapping`.
265
+
266
+
== ConfigProperty
267
+
268
+
While `@ConfigMapping` is the recommended approach, Quarkus also supports
269
+
https://microprofile.io/project/eclipse/microprofile-config[MicroProfile Config] annotations to inject the
201
270
configuration properties in the application.
202
271
203
272
[source,java]
@@ -221,19 +290,20 @@ String suffix;
221
290
@ConfigProperty(name = "greeting.name")
222
291
Optional<String> name; <3>
223
292
----
224
-
<1> If you do not provide a value for this property, the application startup fails with `jakarta.enterprise.inject.spi.DeploymentException: No config value of type [class java.lang.String] exists for: greeting.message`.
293
+
<1> If you do not provide a value for this property, the application startup fails with
294
+
`io.quarkus.runtime.configuration.ConfigurationException: Failed to load config value of type class java.lang.String for: greeting.messagee`.
225
295
<2> The default value is injected if the configuration does not provide a value for `greeting.suffix`.
226
296
<3> This property is optional - an empty `Optional` is injected if the configuration does not provide a value for `greeting.name`.
227
297
228
298
TIP: Use xref:config-mappings.adoc#config-mappings[Config Mappings] to group similar configuration properties.
229
299
230
-
=== Default Values
300
+
== Default Values
231
301
232
-
If a property is associated with a default value (by way of the `defaultValue` attribute), and no configuration value
233
-
is supplied for the property, then rather than throwing a `jakarta.enterprise.inject.spi.DeploymentException`, the
234
-
default value will be used. The `defaultValue` value is expressed as a `String`, and uses the same conversion mechanism
235
-
used to process configuration values. Several Built-in Converters already exist for primitives, boxed primitives, and
236
-
other classes; for example:
302
+
If a configuration is associated with a default value (by way of the `io.smallrye.config.WithDefault` or
303
+
`org.eclipse.microprofile.config.inject.ConfigProperty.defaultValue`), and no configuration value is supplied for the
304
+
property, then rather than throwing an exception, the default value will be used. A default value is expressed as a
305
+
`String`, and uses the same conversion mechanism used to process configuration values. Several Built-in Converters
306
+
already exist for primitives, boxed primitives, and other classes; for example:
237
307
238
308
* Primitives: `boolean`, `byte`, `short`, etc.
239
309
* Boxed primitives: `java.lang.Boolean`, `java.lang.Byte`, `java.lang.Short`, etc.
@@ -248,10 +318,10 @@ these converters comply with the Microprofile or custom implementation providers
248
318
* Boolean values will be `true` in cases "true", "1", "YES", "Y" "ON". Otherwise, value will be interpreted as false
249
319
* For float and double values the fractional digits must be separated by a dot `.`
250
320
251
-
Note that when a combination of `Optional*` types and the `defaultValue` attribute are used, the defined `defaultValue`
252
-
will still be used and if no value is given for the property, the `Optional*` will be present and populated with the
253
-
converted default value. However, when the property is explicitly empty, the default value is not used and the
254
-
`Optional` will be empty. Consider this example:
321
+
Note that when a combination of `Optional*` types and defaults are used, the defined default value will still be used
322
+
and if no value is given for the property, the `Optional*` will be present and populated with the converted default
323
+
value. However, when the property is explicitly empty, the default value is not used and the `Optional` will be empty.
324
+
Consider this example:
255
325
256
326
[source,properties]
257
327
----
@@ -274,23 +344,16 @@ greeting.suffix=
274
344
will result in a `java.util.NoSuchElementException: SRCFG02004: Required property greeting.message not found` on
275
345
startup and the default value will not be assigned.
276
346
277
-
Below is an example of a Quarkus-supplied converter:
<1> The command will run with the `prod-aws` profile. This can be overridden using the `quarkus.profile` configuration.
762
+
763
+
[IMPORTANT]
764
+
====
765
+
Using a different configuration profile at runtime from the one used to build the application can lead to unexpected
766
+
results.
767
+
====
768
+
769
+
== Change configuration after build (Reaugmentation)
688
770
689
-
If you are in the rare situation that you need to change the build time configuration after your application is built, then check out how xref:reaugmentation.adoc[re-augmentation] can be used to rebuild the augmentation output for a different build time configuration.
771
+
If you are in the rare situation that you need to change the build time configuration after your application is built,
772
+
then check out how xref:reaugmentation.adoc[re-augmentation] can be used to rebuild the augmentation output for a
773
+
different build time configuration.
690
774
691
775
== Tracking effective build time configuration used at build time
Copy file name to clipboardExpand all lines: _guides/opentelemetry-metrics.adoc
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -362,9 +362,9 @@ IMPORTANT: Each unique combination of metric name and dimension produces a uniqu
362
362
Using an unbounded set of dimensional data (many different values like a userId) can lead to a "cardinality explosion", an exponential increase in the creation of new time series.
363
363
Avoid!
364
364
365
-
OpenTelemetry provides many other types of Counters: `LongUpDownCounter`, `DoubleCounter`, `DoubleUpDownCounter` and also Observable, async counters like `ObservableLongCounter`, `ObservableDoubleCounter`, `ObservableLongUpDownCounter` and `ObservableDoubleUpDownCounter`.
365
+
OpenTelemetry provides many other types of Counters: `LongUpDownCounter`, `DoubleCounter`, `UpDownCounter`, `DoubleUpDownCounter` and also Observable, async counters like `ObservableLongCounter`, `ObservableDoubleCounter`, `ObservableLongUpDownCounter` and `ObservableDoubleUpDownCounter`.
366
366
367
-
For more details please refer to the https://opentelemetry.io/docs/languages/java/instrumentation/#using-counters[OpenTelemetry Java documentation about Counters].
367
+
For more details please refer to the https://opentelemetry.io/docs/languages/java/api/#counter[OpenTelemetry Java documentation about Counters].
368
368
369
369
=== Gauges
370
370
Observable Gauges should be used to measure non-additive values.
Copy file name to clipboardExpand all lines: _guides/rest.adoc
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -917,6 +917,15 @@ See <<execution-model,Execution Model documentation>> for more information.
917
917
The link:{jdkapi}/java/util/concurrent/CompletionStage.html[`CompletionStage`] return
918
918
type is also supported.
919
919
920
+
==== Request cancellation
921
+
922
+
Async endpoints that return `Uni` support request cancellation, which means that if the underlying HTTP connection is closed for whatever reason,
923
+
the request pipeline defined by the returned `Uni` is also cancelled. This can be very useful in avoiding unnecessary work on the server
924
+
when the client isn't going to use the response anyway.
925
+
926
+
If instead of cancelling the pipeline, it should be completed regardless of the state of the HTTP connection, Quarkus REST provides the `org.jboss.resteasy.reactive.server.Cancellable` annotation
927
+
which can be applied to REST classes or methods to control the cancellation behavior.
928
+
920
929
=== Streaming support
921
930
922
931
If you want to stream your response element by element, you can make your endpoint method return a
0 commit comments