Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
quarkus: add kafka template. (#765)
Browse files Browse the repository at this point in the history
* Add `kafka` template.

* Update stack version

* update stack version

Co-authored-by: Kamran Shamsi <[email protected]>
  • Loading branch information
ianpartridge and Kamran64 authored May 1, 2020
1 parent 96bd1f7 commit cd5fe3c
Show file tree
Hide file tree
Showing 13 changed files with 822 additions and 3 deletions.
39 changes: 38 additions & 1 deletion incubator/quarkus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,44 @@ See: https://quarkus.io/
## Templates

Templates are used to create your local project and start your development. When initializing your project you will be provided with the default template project. This template provides a simple Java application with a JAX-RS "Hello World!" REST API example and a simple HTML welcome page.
Templates are used to create your local project and start your development. This stack provides two templates you can choose from: `default` and `kafka`. If you do not specify a template, the `default` template will be used.

### `default` template

This template provides a simple Java application with a JAX-RS "Hello World!" REST API example and a simple HTML welcome page.

### `kafka` template

This template provides a Java application which demonstrates using MicroProfile Reactive Messaging to consume and produce messages on Kafka topics. The application uses the example from the [Quarkus Kafka guide](https://quarkus.io/guides/kafka).

A bean produces a random `Integer` onto a Reactive Messaging channel named "generated-price" every 5 seconds. This channel is connected to a Kafka topic named "prices". Another bean consumes from that topic, applies a conversion, and publishes a `double` onto another channel named "my-data-stream". Finally, that channel is streamed to a JAX-RS endpoint `/prices.html`, using [Server-sent Events](https://en.wikipedia.org/wiki/Server-sent_events).

#### Running locally

The template provides a sample `docker-compose.yaml` which you can use to run a single-node Kafka cluster on your local machine. To start Kafka locally, run `docker-compose up`. This will start Kafka, Zookeeper, and also create a Docker network on your machine, which you can find the name of by running `docker network list`.

To run the application using Appsody, use this command, substituting in the name of your Docker network:

`$ appsody run --network network_name --docker-options "--env KAFKA_BOOTSTRAP_SERVERS=kafka:9092"`

To shut down Kafka and Zookeeper afterwards, run `docker-compose down`.

#### Running on Kubernetes

To run on Kubernetes, you will first need to deploy Kafka. The easiest way to do that is to use the [Strimzi operator quickstart](https://strimzi.io/quickstarts/). This will deploy a basic Kafka cluster into a `kafka` namespace on your Kubernetes cluster.

You will need to inject the address of your Kafka into your Quarkus application via the `KAFKA_BOOTSTRAP_SERVERS` environment variable. To do this, you can add an `env:` section to your `app-deploy.yaml` that is generated when you run `appsody build`.

```yaml
spec:
env:
- name: KAFKA_BOOTSTRAP_SERVERS
value: my-cluster-kafka-bootstrap.default.svc:9092
```
To get the `value` you need, you can run `kubectl describe kafka -n kafka` and examine the listener address in the status section.

Once you have updated your `app-deploy.yaml` to inject the environment variable, you can run `appsody deploy` to run your Quarkus application on Kubernetes.

## Getting Started

Expand Down
2 changes: 1 addition & 1 deletion incubator/quarkus/image/project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>dev.appsody</groupId>
<artifactId>quarkus</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
<packaging>pom</packaging>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion incubator/quarkus/stack.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Quarkus
version: 0.3.2
version: 0.3.3
description: Quarkus runtime for running Java applications
license: Apache-2.0
language: java
Expand Down
47 changes: 47 additions & 0 deletions incubator/quarkus/templates/kafka/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Appsody: run",
"type": "shell",
"command": "appsody run",
"group": "build",
"problemMatcher": []
},
{
"label": "Appsody: debug",
"type": "shell",
"command": "appsody debug",
"group": "build",
"problemMatcher": []
},
{
"label": "Appsody: test",
"type": "shell",
"command": "appsody test",
"group": "test",
"problemMatcher": []
},
{
"label": "Appsody: build",
"type": "shell",
"command": "appsody build",
"group": "build",
"problemMatcher": []
},
{
"label": "Appsody: deploy",
"type": "shell",
"command": "appsody deploy",
"group": "build",
"problemMatcher": []
},
{
"label": "Appsody: stop",
"type": "shell",
"command": "appsody stop",
"group": "build",
"problemMatcher": []
}
]
}
30 changes: 30 additions & 0 deletions incubator/quarkus/templates/kafka/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: '2'

services:

zookeeper:
image: strimzi/kafka:0.15.0-kafka-2.3.1
command: [
"sh", "-c",
"bin/zookeeper-server-start.sh config/zookeeper.properties"
]
ports:
- "2181:2181"
environment:
LOG_DIR: /tmp/logs

kafka:
image: strimzi/kafka:0.15.0-kafka-2.3.1
command: [
"sh", "-c",
"bin/kafka-server-start.sh config/server.properties --override listeners=$${KAFKA_LISTENERS} --override advertised.listeners=$${KAFKA_ADVERTISED_LISTENERS} --override zookeeper.connect=$${KAFKA_ZOOKEEPER_CONNECT}"
]
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
LOG_DIR: "/tmp/logs"
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
Loading

0 comments on commit cd5fe3c

Please sign in to comment.