Skip to content

Commit

Permalink
WildFly mini series: REST Client - review
Browse files Browse the repository at this point in the history
  • Loading branch information
tommaso-borgato committed Nov 29, 2024
1 parent 94f5640 commit 67aa8e7
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@
:version-wildfly: 34.0.1.Final
:version-wildfly-galleon-pack: 34.0.1.Final
:jakarta-jakartaee-api-version: 10.0.0
:version-junit-jupiter-api: 5.10.2
:version-arquillian-junit5-container: 1.8.0.Final
:version-org-wildfly-arquillian-wildfly-arquillian: 5.1.0.Beta1
:version-resteasy-client: 6.2.7.Final
:version-junit-jupiter-api: 5.11.3
:version-wildfly-cloud-galleon-pack: 7.0.2.Final
:version-wildfly-maven-plugin: 5.0.1.Final
:version-wildfly-maven-plugin-docs: 5.1
:my-jaxrs-app-docker-image-name: my-jaxrs-app
:my-jaxrs-app-db-docker-image-name: my-jaxrs-app-db
:my-jaxrs-app-infinispan-docker-image-name: my-jaxrs-app-infinispan
:quay-io-account-name: tborgato
:version-wildfly-datasources-galleon-pack: 8.0.0.Final
:version-wildfly-datasources-galleon-pack: 9.1.0.Final
:postgre-sql-user: postgres
:postgre-sql-password: admin
:postgre-sql-host: localhost
Expand Down Expand Up @@ -47,8 +44,8 @@
:artemis-console-port-name: artemis-console-port
:my-jms-app-docker-image-name: my-jms-app
:podman-network-name: demo-network
:my-jaxrs-app-docker-image-name-client: my-jaxrs-app-client
:my-jaxrs-app-docker-image-name-server: my-jaxrs-app-server
:my-jakarta-rest-docker-image-name-client: my-jakarta-rest-client
:my-jakarta-rest-docker-image-name-server: my-jakarta-rest-server
:simple-microservice-client-secured: simple-microservice-client-secured
:simple-microservice-server-secured: simple-microservice-server-secured
:keycloak-external: keycloak-external
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
:simple-microservice-header: WildFly Java Microservice
:simple-microservice-part1: WildFly Java Microservice - PART 1: Docker Image
:simple-microservice-part1: WildFly Java Microservice - PART 1: Container Image
:simple-microservice-part2: WildFly Java Microservice - PART 2: Kubernetes
:simple-microservice-database-header: Connecting to a DB
:simple-microservice-database-part1: Connecting to a DB - PART 1: Docker Image
:simple-microservice-database-part1: Connecting to a DB - PART 1: Container Image
:simple-microservice-database-part2: Connecting to a DB - PART 2: Kubernetes
:simple-microservice-jms-header: Using a Message Broker
:simple-microservice-jms-part1: Using a Message Broker - PART 1: Docker Image
:simple-microservice-jms-part1: Using a Message Broker - PART 1: Container Image
:simple-microservice-jms-part2: Using a Message Broker - PART 2: Kubernetes
:simple-microservice-infinispan-header: Using Infinispan remote cache
:simple-microservice-infinispan-part1: Using Infinispan remote cache - PART 1: Docker Image
:simple-microservice-infinispan-part1: Using Infinispan remote cache - PART 1: Container Image
:simple-microservice-infinispan-part2: Using Infinispan remote cache - PART 2: Kubernetes
:simple-microservice-client-header: Invoke one Microservices from another
:simple-microservice-client-part1: Invoke one Microservices from another - PART 1: Docker Images
:simple-microservice-client-part1: Invoke one Microservices from another - PART 1: Container Images
:simple-microservice-client-part2: Invoke one Microservices from another - PART 2: Kubernetes
:simple-microservice-client-part3: Invoke one Microservices from another - PART 3: Propagate Authentication
:get-enterprise-ready: Get “Enterprise” ready
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Since you copied {source-code-git-repository}/simple-microservice[simple-microse

[source,bash,subs="normal"]
----
podman build -t {my-jaxrs-app-docker-image-name-server}:latest .
podman build -t {my-jakarta-rest-docker-image-name-server}:latest .
----

NOTE: You can use link:https://docs.wildfly.org/wildfly-maven-plugin/releases/{version-wildfly-maven-plugin-docs}/image-mojo.html[`wildfly-maven-plugin`, window="_blank"] to automate the image build
Expand All @@ -94,8 +94,8 @@ Then we run our container using this network:
----
podman run --rm -p 8180:8080 -p 10090:9990 \
--network={podman-network-name} \
--name={my-jaxrs-app-docker-image-name-server} \
{my-jaxrs-app-docker-image-name-server}
--name={my-jakarta-rest-docker-image-name-server} \
{my-jakarta-rest-docker-image-name-server}
----

== Microservice A - the client
Expand All @@ -111,15 +111,15 @@ NOTE: we remove tests because, since we are going to introduce service to servic

==== pom.xml

Set `<artifactId>simple-microservice-client</artifactId>`;
Update the artifactId to `<artifactId>simple-microservice-client</artifactId>`;

Add the following to `dependencyManagement`:

[source,xml,subs="normal"]
----
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-microprofile</artifactId>
<artifactId>wildfly-expansion</artifactId>
<version>${version.wildfly.bom}</version>
<type>pom</type>
<scope>import</scope>
Expand Down Expand Up @@ -174,7 +174,7 @@ NOTE: `simple-microservice-server-uri` would pick up its value, whenever set, fr

Add the following interface:

.GettingStartedEndpointInterface.java:
.GettingStartedEndpointClient.java:
[source,java]
----
package org.wildfly.examples;
Expand All @@ -189,11 +189,11 @@ import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
@RegisterRestClient(configKey="simple-microservice-server")
@Path("/hello")
public interface GettingStartedEndpointInterface {
public interface GettingStartedEndpointClient {
@GET
@Path("/{name}")
@Produces(MediaType.TEXT_PLAIN)
public Response sayHello(final @PathParam("name") String name);
Response sayHello(@PathParam("name") String name);
}
----

Expand Down Expand Up @@ -222,7 +222,7 @@ public class GettingStartedEndpoint {
@Inject
@RestClient
private GettingStartedEndpointInterface service;
private GettingStartedEndpointClient service;
@GET
@Path("/{name}")
Expand All @@ -248,33 +248,35 @@ mvn clean package

Since you copied {source-code-git-repository}/simple-microservice[simple-microservice], the Dockerfile from link:https://github.com/wildfly/wildfly-s2i/blob/main/examples/docker-build/Dockerfile[examples/docker-build/Dockerfile, window="_blank"] should already be at the root of your project;

==== Build the Docker Image `{my-jaxrs-app-docker-image-name-client}:latest` with the following command:
==== Build the Docker Image `{my-jakarta-rest-docker-image-name-client}:latest` with the following command:

[source,bash,subs="normal"]
----
podman build -t {my-jaxrs-app-docker-image-name-client}:latest .
podman build -t {my-jakarta-rest-docker-image-name-client}:latest .
----

NOTE: You can use link:https://docs.wildfly.org/wildfly-maven-plugin/releases/{version-wildfly-maven-plugin-docs}/image-mojo.html[`wildfly-maven-plugin`, window="_blank"] to automate the image build

==== Run the Docker Image

[source,bash,subs="normal"]
----
podman run --rm -p 8080:8080 -p 9990:9990 \
--network={podman-network-name} \
--env "SIMPLE_MICROSERVICE_SERVER_URI=http://{my-jaxrs-app-docker-image-name-server}:8080/hello" \
--name={my-jaxrs-app-docker-image-name-client} \
{my-jaxrs-app-docker-image-name-client}
--env "SIMPLE_MICROSERVICE_SERVER_URI=http://{my-jakarta-rest-docker-image-name-server}:8080/hello" \
--name={my-jakarta-rest-docker-image-name-client} \
{my-jakarta-rest-docker-image-name-client}
----

NOTE: The **{my-jaxrs-app-docker-image-name-server}** container can be reached, inside the **{podman-network-name}** network, using the DNS name **{my-jaxrs-app-docker-image-name-server}**
NOTE: The **{my-jakarta-rest-docker-image-name-server}** container can be reached, inside the **{podman-network-name}** network, using the DNS name **{my-jakarta-rest-docker-image-name-server}**

== Test

Open http://localhost:8080[http://localhost:8080] in your browser: this web page is served by the **{my-jaxrs-app-docker-image-name-client}** container;
Open http://localhost:8080[http://localhost:8080] in your browser: this web page is served by the **{my-jakarta-rest-docker-image-name-client}** container;

Write something in the "Name" input box and then press "Say Hello": the response you'll see will come from **{my-jaxrs-app-docker-image-name-server}** container!
Write something in the "Name" input box and then press "Say Hello": the response you'll see will come from **{my-jakarta-rest-docker-image-name-server}** container!

The complete invocation chain is "**web browser** -> **{my-jaxrs-app-docker-image-name-client}** -> **{my-jaxrs-app-docker-image-name-server}**"
The complete invocation chain is "**web browser** -> **{my-jakarta-rest-docker-image-name-client}** -> **{my-jakarta-rest-docker-image-name-server}**"

== What's next?

Expand Down
Loading

0 comments on commit 67aa8e7

Please sign in to comment.