Skip to content

Commit a93215c

Browse files
committed
quote quickstart
1 parent 64a1753 commit a93215c

32 files changed

+777
-347
lines changed

kafka-quickstart/README.md

+40-12
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,57 @@ Quarkus Kafka Quickstart
33

44
This project illustrates how you can interact with Apache Kafka using MicroProfile Reactive Messaging.
55

6-
76
## Start the application
87

9-
The application can be started using:
8+
The application is composed of two microservices. They can be started using:
9+
10+
```bash
11+
mvn -f producer quarkus:dev
12+
```
13+
14+
and
1015

1116
```bash
12-
mvn quarkus:dev
17+
mvn -f processor quarkus:dev
1318
```
1419

1520
_NOTE_: Quarkus Dev Services starts a Kafka broker for you automatically.
1621

17-
Then, open your browser to `http://localhost:8080/prices.html`, and you should see a fluctuating price.
22+
Then, open your browser to `http://localhost:8080/quotes.html`.
23+
You can send quote requests and observe received quotes.
1824

1925
## Anatomy
2026

21-
In addition to the `prices.html` page, the application is composed by 3 components:
27+
The application is composed of the following microservices:
28+
29+
#### Producer
30+
31+
* `QuoteProducer` generates uniquely identified quote requests and sends them to the Kafka topic `quote-requests`.
32+
It also consumes the Kafka topic `quotes` and relays received messages to the browser using Server-Sent Events.
33+
* `quotes.html` sends quote requests to the previous endpoint and updates quotes with received prices.
34+
35+
#### Processor
36+
37+
* `QuoteProcessor` consumes quote request id's from the `quote-requests` Kafka topic and responds back to the `quotes` topic with a `Quote` object containing a random price.
2238

23-
* `PriceGenerator` - a bean generating random price. They are sent to a Kafka topic
24-
* `PriceConverter` - on the consuming side, the `PriceConverter` receives the Kafka message and convert the price.
25-
The result is sent to an in-memory stream of data
26-
* `PriceResource` - the `PriceResource` retrieves the in-memory stream of data in which the converted prices are sent and send these prices to the browser using Server-Sent Events.
39+
Interactions with Kafka is managed by MicroProfile Reactive Messaging.
40+
Application configurations are located in `application.properties` files.
41+
42+
## Running the application in Docker
43+
44+
To run the application on Docker:
45+
46+
First make sure that both services are packaged:
47+
```bash
48+
mvn clean package
49+
```
50+
51+
Then lauch the Docker compose:
52+
```bash
53+
docker compose up
54+
```
2755

28-
The interaction with Kafka is managed by MicroProfile Reactive Messaging.
29-
The configuration is located in the application configuration.
56+
This will create a single-node Kafka cluster and launch both microservices.
3057

3158
## Running in native
3259

@@ -38,4 +65,5 @@ As you are running in _prod_ mode, you need a Kafka cluster. You can follow the
3865

3966
Then run with:
4067

41-
`./target/kafka-quickstart-1.0.0-SNAPSHOT-runner`
68+
`./producer/target/kafka-quickstart-producer-1.0.0-SNAPSHOT-runner`
69+
`./processor/target/kafka-quickstart-processor-1.0.0-SNAPSHOT-runner`

kafka-quickstart/docker-compose.yaml

+33-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2'
1+
version: '3.5'
22

33
services:
44

@@ -12,6 +12,8 @@ services:
1212
- "2181:2181"
1313
environment:
1414
LOG_DIR: /tmp/logs
15+
networks:
16+
- kafkaquickstart-network
1517

1618
kafka:
1719
image: quay.io/strimzi/kafka:0.23.0-kafka-2.8.0
@@ -25,6 +27,34 @@ services:
2527
- "9092:9092"
2628
environment:
2729
LOG_DIR: "/tmp/logs"
28-
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
30+
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
2931
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
30-
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
32+
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
33+
networks:
34+
- kafkaquickstart-network
35+
36+
producer:
37+
image: quarkus-quickstarts/kafka-quickstart-producer:1.0
38+
build:
39+
context: producer
40+
dockerfile: src/main/docker/Dockerfile.${QUARKUS_MODE:-jvm}
41+
environment:
42+
KAFKA_BOOTSTRAP_SERVERS: kafka:9092
43+
ports:
44+
- "8080:8080"
45+
networks:
46+
- kafkaquickstart-network
47+
48+
processor:
49+
image: quarkus-quickstarts/kafka-quickstart-processor:1.0
50+
build:
51+
context: processor
52+
dockerfile: src/main/docker/Dockerfile.${QUARKUS_MODE:-jvm}
53+
environment:
54+
KAFKA_BOOTSTRAP_SERVERS: kafka:9092
55+
networks:
56+
- kafkaquickstart-network
57+
58+
networks:
59+
kafkaquickstart-network:
60+
name: kafkaquickstart

kafka-quickstart/pom.xml

+5-151
Original file line numberDiff line numberDiff line change
@@ -5,155 +5,9 @@
55
<groupId>org.acme</groupId>
66
<artifactId>kafka-quickstart</artifactId>
77
<version>1.0.0-SNAPSHOT</version>
8-
<properties>
9-
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
10-
<quarkus-plugin.version>999-SNAPSHOT</quarkus-plugin.version>
11-
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
12-
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
13-
<quarkus.platform.version>999-SNAPSHOT</quarkus.platform.version>
14-
<maven.compiler.source>11</maven.compiler.source>
15-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16-
<maven.compiler.target>11</maven.compiler.target>
17-
<testcontainers.version>1.15.2</testcontainers.version>
18-
</properties>
19-
<dependencyManagement>
20-
<dependencies>
21-
<dependency>
22-
<groupId>${quarkus.platform.group-id}</groupId>
23-
<artifactId>${quarkus.platform.artifact-id}</artifactId>
24-
<version>${quarkus.platform.version}</version>
25-
<type>pom</type>
26-
<scope>import</scope>
27-
</dependency>
28-
</dependencies>
29-
</dependencyManagement>
30-
<dependencies>
31-
<dependency>
32-
<groupId>io.quarkus</groupId>
33-
<artifactId>quarkus-resteasy-reactive</artifactId>
34-
</dependency>
35-
<dependency>
36-
<groupId>io.quarkus</groupId>
37-
<artifactId>quarkus-smallrye-reactive-messaging-kafka</artifactId>
38-
</dependency>
39-
<dependency>
40-
<groupId>io.quarkus</groupId>
41-
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
42-
</dependency>
43-
<dependency>
44-
<groupId>io.quarkus</groupId>
45-
<artifactId>quarkus-junit5</artifactId>
46-
<scope>test</scope>
47-
</dependency>
48-
<dependency>
49-
<groupId>io.quarkus</groupId>
50-
<artifactId>quarkus-smallrye-health</artifactId>
51-
</dependency>
52-
<dependency>
53-
<groupId>org.jboss.resteasy</groupId>
54-
<artifactId>resteasy-client</artifactId>
55-
<scope>test</scope>
56-
</dependency>
57-
<dependency>
58-
<groupId>io.rest-assured</groupId>
59-
<artifactId>rest-assured</artifactId>
60-
<scope>test</scope>
61-
</dependency>
62-
<dependency>
63-
<groupId>org.awaitility</groupId>
64-
<artifactId>awaitility</artifactId>
65-
<scope>test</scope>
66-
</dependency>
67-
</dependencies>
68-
<build>
69-
<plugins>
70-
<plugin>
71-
<groupId>io.quarkus</groupId>
72-
<artifactId>quarkus-maven-plugin</artifactId>
73-
<version>${quarkus-plugin.version}</version>
74-
<executions>
75-
<execution>
76-
<goals>
77-
<goal>build</goal>
78-
</goals>
79-
</execution>
80-
</executions>
81-
</plugin>
82-
<plugin>
83-
<artifactId>maven-surefire-plugin</artifactId>
84-
<version>${surefire-plugin.version}</version>
85-
<configuration>
86-
<systemPropertyVariables>
87-
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
88-
<maven.home>${maven.home}</maven.home>
89-
</systemPropertyVariables>
90-
</configuration>
91-
</plugin>
92-
</plugins>
93-
</build>
94-
<profiles>
95-
<profile>
96-
<id>native</id>
97-
<activation>
98-
<property>
99-
<name>native</name>
100-
</property>
101-
</activation>
102-
<properties>
103-
<quarkus.package.type>native</quarkus.package.type>
104-
</properties>
105-
<build>
106-
<plugins>
107-
<plugin>
108-
<artifactId>maven-failsafe-plugin</artifactId>
109-
<version>${surefire-plugin.version}</version>
110-
<executions>
111-
<execution>
112-
<goals>
113-
<goal>integration-test</goal>
114-
<goal>verify</goal>
115-
</goals>
116-
<configuration>
117-
<systemPropertyVariables>
118-
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
119-
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
120-
<maven.home>${maven.home}</maven.home>
121-
</systemPropertyVariables>
122-
</configuration>
123-
</execution>
124-
</executions>
125-
</plugin>
126-
</plugins>
127-
</build>
128-
</profile>
129-
<profile>
130-
<id>docker</id>
131-
<activation>
132-
<property>
133-
<name>start-containers</name>
134-
</property>
135-
</activation>
136-
<build>
137-
<plugins>
138-
<plugin>
139-
<groupId>org.codehaus.mojo</groupId>
140-
<artifactId>exec-maven-plugin</artifactId>
141-
<version>3.0.0</version>
142-
<executions>
143-
<execution>
144-
<id>docker-prune</id>
145-
<phase>generate-resources</phase>
146-
<goals>
147-
<goal>exec</goal>
148-
</goals>
149-
<configuration>
150-
<executable>${basedir}/../.github/docker-prune.sh</executable>
151-
</configuration>
152-
</execution>
153-
</executions>
154-
</plugin>
155-
</plugins>
156-
</build>
157-
</profile>
158-
</profiles>
8+
<packaging>pom</packaging>
9+
<modules>
10+
<module>producer</module>
11+
<module>processor</module>
12+
</modules>
15913
</project>

0 commit comments

Comments
 (0)