Skip to content

Commit

Permalink
Migration to Quarkus 2 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarting authored Jul 9, 2021
1 parent 90bbd29 commit a6eef4f
Show file tree
Hide file tree
Showing 20 changed files with 180 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

This repo is a fork of the original one based in [Spring Boot](https://github.com/rmarting/kafka-clients-sb-sample)
but refactored to be a full-compliant [Quarkus](https://quarkus.io/) application. This repo is described in
[Integrating Quarkus and Apicurio Service Registry](https://blog.jromanmartin.io/2020/12/18/integrating-quarkus-and-apicurio-service-registry.html) blog post.
[Integrating Quarkus and Apicurio Service Registry](https://blog.jromanmartin.io/2020/12/18/integrating-quarkus-and-apicurio-service-registry.html)
blog post.

The following components were refactored from Spring Boot to Quarkus Extensions:

Expand All @@ -20,7 +21,8 @@ The following components were refactored from Spring Boot to Quarkus Extensions:
This new version is really fast (less than 2 seconds) ... like a :rocket:

```text
2021-06-24 07:56:54,886 INFO [io.quarkus] (main) kafka-clients-quarkus-sample 2.0.0-SNAPSHOT on JVM (powered by Quarkus 1.13.7.Final) started in 1.756s. Listening on: http://0.0.0.0:8181
Jun 30, 2021 9:57:02 PM io.quarkus.bootstrap.runner.Timing printStartupTime
INFO: kafka-clients-quarkus-sample 2.0.0-SNAPSHOT on JVM (powered by Quarkus 2.0.0.Final) started in 1.755s. Listening on: http://0.0.0.0:8181
```

## :rocket: :sparkles: :rotating_light: QUARKUS EDITION :rotating_light: :sparkles: :rocket:
Expand Down Expand Up @@ -298,7 +300,7 @@ To register the schemas in Service Registry running in OpenShift:
❯ ./mvnw clean generate-sources -Papicurio
```

The next screenshot shows the schemas registed in the Web Console:
The next screenshot shows the schemas registered in the Web Console:

![Artifacts registered in Apicurio Registry](./img/apicurio-registry-artifacts.png)

Expand Down Expand Up @@ -370,21 +372,29 @@ Or you can deploy into Kubernetes or OpenShift platform using [Eclipse JKube](ht
To deploy the application using the Kubernetes Maven Plug-In:

```shell
❯ ./mvnw package k8s:resource k8s:build k8s:push k8s:apply -Pkubernetes -Djkube.build.strategy=jib
eval $(minikube docker-env)
❯ kubectl create -f src/main/k8s/role.yml
❯ ./mvnw package k8s:resource k8s:build k8s:apply -Pkubernetes
```

If you want to deploy the native version of this project:

```shell
eval $(minikube docker-env)
❯ kubectl create -f src/main/k8s/role.yml
❯ ./mvnw package k8s:resource k8s:build k8s:apply -Pnative,kubernetes
```

To deploy the application using the OpenShift Maven Plug-In (only valid for OpenShift Platform):

```shell script
❯ ./mvnw package oc:resource oc:build oc:apply -Popenshift,native -Dquarkus.native.container-build=true
❯ ./mvnw package oc:resource oc:build oc:apply -Popenshift
```

To deploy the application in Minikube:
If you want to deploy the native version of this project:

```shell script
eval $(minikube docker-env)
❯ kubectl create -f src/main/k8s/role.yml
❯ ./mvnw package k8s:resource k8s:build k8s:apply -Pkubernetes
❯ ./mvnw package oc:resource oc:build oc:apply -Pnative,openshift -Dquarkus.native.container-build=true
```

# REST API
Expand Down Expand Up @@ -503,8 +513,8 @@ With Minikube:
}
```

That is! You have been deployed a full stack of components to produce and consume checked and valid messages using
a schema declared. Congratulations!.
That's all folks! You have been deployed a full stack of components to produce and consume checked and
valid messages using a schema declared. Congratulations!.

## Main References

Expand All @@ -517,4 +527,5 @@ a schema declared. Congratulations!.
* [Quarkus - Using OpenAPI and Swagger UI](https://quarkus.io/guides/openapi-swaggerui)
* [Quarkus - Contexts and Dependency Injection](https://quarkus.io/guides/cdi-reference)
* [Quarkus - Using Apache Kafka with Reactive Messaging](https://quarkus.io/guides/kafka)
* [Quarkus - How to Use Kafka, Schema Registry and Avro with Quarkus](https://quarkus.io/blog/kafka-avro/)
* [Quarkus - Configuring your application](https://quarkus.io/guides/config)
2 changes: 1 addition & 1 deletion mvnw
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
Expand Down
2 changes: 1 addition & 1 deletion mvnw.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
Expand Down
67 changes: 36 additions & 31 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<jkube.generator.name>${project.artifactId}:${project.version}</jkube.generator.name>
<jkube.generator.quarkus.webPort>8181</jkube.generator.quarkus.webPort>
<!-- Quarkus -->
<quarkus.platform.version>1.13.7.Final</quarkus.platform.version>
<quarkus.platform.version>2.0.1.Final</quarkus.platform.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -83,6 +83,12 @@
<artifactId>quarkus-avro</artifactId>
</dependency>

<!-- Apicurio Registry Avro Schemas Extension -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-apicurio-registry-avro</artifactId>
</dependency>

<!-- Apicurio Serializers/Deserializers -->
<dependency>
<groupId>io.apicurio</groupId>
Expand All @@ -91,7 +97,21 @@
</dependency>

<!-- Test Dependencies -->
<!-- TODO -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-reactive-messaging-in-memory</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -112,13 +132,15 @@
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<parameters>${maven.compiler.parameters}</parameters>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
Expand All @@ -128,34 +150,13 @@
</systemPropertyVariables>
</configuration>
</plugin>

<!-- Avro Maven Plug-In to generate classes from schemas (files *.avsc) -->
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<executions>
<execution>
<!-- Generate Java Classes in generate-sources maven phase -->
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<!-- Source Folder with Avro Schemas -->
<sourceDirectory>${project.basedir}/src/main/resources/schemas</sourceDirectory>
<includes>
<!-- Avro Schemas extension file pattern -->
<include>**/*.avsc</include>
</includes>
<outputDirectory>${project.build.directory}/generated-sources/schemas</outputDirectory>
<stringType>String</stringType>
</configuration>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>${surefire-plugin.version}</version>
</plugin>

<!-- Extending source resources to add generated classes by Avro -->
<!-- Extending source resources to add generated classes by Quarkus Avro -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand All @@ -171,7 +172,7 @@
<configuration>
<sources>
<!-- Output folder defined in generate phase -->
<source>${project.build.directory}/generated-sources/schemas</source>
<source>${project.build.directory}/generated-sources/avsc</source>
</sources>
</configuration>
</execution>
Expand Down Expand Up @@ -203,9 +204,10 @@
<artifact>
<groupId>default</groupId>
<artifactId>messages</artifactId>
<version>2.0</version>
<type>AVRO</type>
<file>
${project.basedir}/src/main/resources/schemas/message.avsc
${project.basedir}/src/main/avro/message.avsc
</file>
<ifExists>RETURN_OR_UPDATE</ifExists>
<canonicalize>true</canonicalize>
Expand All @@ -215,9 +217,10 @@
<artifact>
<groupId>default</groupId>
<artifactId>messages-value</artifactId>
<version>2.0</version>
<type>AVRO</type>
<file>
${project.basedir}/src/main/resources/schemas/message.avsc
${project.basedir}/src/main/avro/message.avsc
</file>
<ifExists>RETURN_OR_UPDATE</ifExists>
<canonicalize>true</canonicalize>
Expand All @@ -227,9 +230,10 @@
<artifact>
<groupId>io.jromanmartin.kafka.schema.avro</groupId>
<artifactId>Message</artifactId>
<version>2.0</version>
<type>AVRO</type>
<file>
${project.basedir}/src/main/resources/schemas/message.avsc
${project.basedir}/src/main/avro/message.avsc
</file>
<ifExists>RETURN_OR_UPDATE</ifExists>
<canonicalize>true</canonicalize>
Expand Down Expand Up @@ -282,6 +286,7 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/kafka-clients-quarkus-sample .
# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/kafka-clients-quarkus-sample-jvm .
#
# Then run the container using:
#
Expand All @@ -21,7 +21,7 @@
# docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/kafka-clients-quarkus-sample-jvm
#
###
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.4

ARG JAVA_PACKAGE=java-11-openjdk-headless
ARG RUN_JAVA_VERSION=1.3.8
Expand Down Expand Up @@ -52,3 +52,4 @@ EXPOSE 8080
USER 1001

ENTRYPOINT [ "/deployments/run-java.sh" ]

2 changes: 1 addition & 1 deletion src/main/docker/Dockerfile.legacy-jar
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/kafka-clients-quarkus-sample-legacy-jar
#
###
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.4

ARG JAVA_PACKAGE=java-11-openjdk-headless
ARG RUN_JAVA_VERSION=1.3.8
Expand Down
2 changes: 1 addition & 1 deletion src/main/docker/Dockerfile.native
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# docker run -i --rm -p 8080:8080 quarkus/kafka-clients-quarkus-sample
#
###
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.4
WORKDIR /work/
RUN chown 1001 /work \
&& chmod "g+rwX" /work \
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/io/jromanmartin/kafka/api/ConsumerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ public class ConsumerController {
@ConfigProperty(name = "app.consumer.poolTimeout")
Long poolTimeout;

@Operation(summary = "Get a greeting message")
@APIResponses(value = {
@APIResponse(
responseCode = "200",
description = "Greeting message",
content = @Content(schema = @Schema(implementation = String.class))),
@APIResponse(responseCode = "404", description = "Greeting message not found"),
@APIResponse(responseCode = "500", description = "Internal Server Error")})
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "Hello Consumer!";
}

@Operation(summary = "Get a list of records from a topic")
@APIResponses(value = {
@APIResponse(
Expand All @@ -51,7 +65,7 @@ public Response pollFromTopic(
@Parameter(description = "Topic name", required = true) @PathParam("topicName") String topicName,
@Parameter(description = "Commit results", required = false) @QueryParam("commit") boolean commit,
@Parameter(description = "Partition ID", required = false) @QueryParam("partition") Integer partition) {
MessageListDTO messageListDTO = messageService.pollEvents(topicName, partition, commit);
var messageListDTO = messageService.pollEvents(topicName, partition, commit);

// Prepare response
if (messageListDTO.getMessages().isEmpty()) {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/io/jromanmartin/kafka/api/ProducerController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.jromanmartin.kafka.api;

import io.jromanmartin.kafka.dto.MessageDTO;
import io.jromanmartin.kafka.dto.MessageListDTO;
import io.jromanmartin.kafka.service.MessageService;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.media.Content;
Expand All @@ -14,6 +15,7 @@

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
Expand All @@ -32,6 +34,20 @@ public class ProducerController {
@Inject
MessageService messageService;

@Operation(summary = "Get a greeting message")
@APIResponses(value = {
@APIResponse(
responseCode = "200",
description = "Greeting message",
content = @Content(schema = @Schema(implementation = String.class))),
@APIResponse(responseCode = "404", description = "Greeting message not found"),
@APIResponse(responseCode = "500", description = "Internal Server Error")})
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "Hello Producer!";
}

@Operation(summary = "Send a message synchronously using the Kafka Client Producer API")
@APIResponses(value = {
@APIResponse(
Expand Down
Loading

0 comments on commit a6eef4f

Please sign in to comment.