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: docs/src/main/asciidoc/extension-writing-dev-service.adoc
+73-43Lines changed: 73 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,114 +9,144 @@ include::_attributes.adoc[]
9
9
:categories: writing-extensions
10
10
:diataxis-type: howto
11
11
:topics: extensions
12
-
////
13
-
////
14
12
13
+
Learn how to develop a xref:dev-services.adoc[Dev Service] for your extension in order to replace an external service in development mode.
15
14
16
15
== Prerequisites
17
16
18
-
- You should already have an xref:building-my-first-extension.adoc[extension structure] in place
19
-
- You should have a containerised version of your external service (not all Dev Services rely on containers, but most do)
17
+
:prerequisites-time: 15 minutes
18
+
:prerequisites-docker:
19
+
:prerequisites-no-cli:
20
+
:prerequisites-no-graalvm:
21
+
include::{includes}/prerequisites.adoc[]
22
+
* An xref:building-my-first-extension.adoc[extension structure] in place
23
+
* A containerised version of your external service (not all Dev Services rely on containers, but most do)
20
24
21
25
== Creating a Dev Service
22
26
23
-
If your extension provides APIs for connecting to an external service, it's a good idea to provide a xref:dev-services.adoc[Dev Service] implementation.
27
+
If your extension provides APIs for connecting to an external service, it's a good idea to provide a dev service implementation.
28
+
29
+
First, you must add the following dependency to the build file, in your xref:writing-extensions.adoc#project-setup[deployement] module :
return new DevServicesResultBuildItem.RunningDevService(FEATURE, container.getContainerId(),
44
-
container::close, configOverrides)
45
-
.toBuildItem();
46
-
}
65
+
return new DevServicesResultBuildItem.RunningDevService(FEATURE,
66
+
container.getContainerId(),
67
+
container::close,
68
+
configOverrides).toBuildItem();
69
+
}
47
70
----
48
71
49
72
With this code, you should be able to see your container starting if you add your extension to a test application and run `quarkus dev`.
50
-
However, the application will not be able to connect to it, because no ports are exposed. To expose ports, add `withExposedPorts` to the container construction.
73
+
However, the application will not be able to connect to it, because no ports are exposed.
74
+
To expose ports, add `withExposedPorts` to the container construction.
51
75
For example,
52
76
53
-
[source%nowrap,java]
77
+
[source,java]
54
78
----
55
79
GenericContainer container = new GenericContainer<>(dockerImageName)
Testcontainers will map these ports to random ports on the host. This avoids port conflicts, but presents a new problem – how do applications connect to the service in the container?
83
+
`Testcontainers` will map these ports to random ports on the host.
84
+
This avoids port conflicts, but presents a new problem – how do applications connect to the service in the container?
60
85
61
86
To allow applications to connect, the extension should override the default configuration for the service with the mapped ports.
Waiting for a port to be open is another option. See the link:https://java.testcontainers.org/features/startup_and_waits/[Testcontainers documentation] for a full discussion of wait strategies.
111
+
Waiting for a port to be open is another option.
112
+
See the link:https://java.testcontainers.org/features/startup_and_waits/[Testcontainers documentation] for a full discussion on wait strategies.
84
113
85
114
== Configuring the Dev Service
86
115
87
116
To configure the Dev Service launch process, your build step can accept a `ConfigPhase.BUILD_TIME` config class in its constructor.
0 commit comments