Skip to content

Commit

Permalink
Use apache/kafka for subscription example. Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ryukzak committed Aug 27, 2024
1 parent bfe6294 commit 86252fa
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 27 deletions.
1 change: 1 addition & 0 deletions subscriptions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kafka-data
47 changes: 41 additions & 6 deletions subscriptions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

This is a demo of [Aidbox SubscriptionTopic](https://docs.aidbox.app/modules-1/topic-based-subscriptions/wip-dynamic-subscriptiontopic-with-destinations) integrated with Kafka.

In this example we demonstrate how you can create standard FHIR questionnaire, collecting data from users via web form and receives all responses to the Kafka topic.

Objectives:

1. How to up and running Aidbox and Kafka locally via docker compose.
1. Learn how to collect user answers for **FHIR Questionnaire** via [Aidbox Forms](https://docs.aidbox.app/modules-1/aidbox-forms).
1. Learn how [SubscriptionTopic and TopicDestination](https://docs.aidbox.app/modules-1/topic-based-subscriptions/wip-dynamic-subscriptiontopic-with-destinations) works with Kafka.

<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
**Table of Contents**

- [[WIP] Aidbox SubscriptionTopic with Kafka](#wip-aidbox-subscriptiontopic-with-kafka)
- [Prerequisites](#prerequisites)
- [Step 1: Set Up the Environment](#step-1-set-up-the-environment)
- [Set Up Aidbox](#set-up-aidbox)
- [Run Aidbox, Kafka & Kafka UI](#run-aidbox-kafka--kafka-ui)
- [STEP 2: Set up Subscription and Destination](#step-2-set-up-subscription-and-destination)
- [Create AidboxSubscriptionTopic resource](#create-aidboxsubscriptiontopic-resource)
- [Create TopicDestination resource](#create-topicdestination-resource)
- [Create Kafka Topic](#create-kafka-topic)
- [STEP 3: Feature demonstration](#step-3-feature-demonstration)
- [Submit form](#submit-form)
- [Check TopicDestination status](#check-topicdestination-status)
- [See messages in Kafka UI](#see-messages-in-kafka-ui)

<!-- markdown-toc end -->


## Prerequisites

- [Docker](https://www.docker.com/)
Expand All @@ -23,7 +51,7 @@ Add the license key (AIDBOX_LICENSE) to the .env file.
### Run Aidbox, Kafka & Kafka UI

```shell
docker compose up
docker compose up
```

- Aidbox will be available on <http://localhost:8888/>
Expand All @@ -32,6 +60,11 @@ docker compose up
- Kafka UI will be available on <http://localhost:8080/>
- Kafka will be available on `http://localhost:9092/`

Additionally, the docker compose file makes initial setup for Kafka and Aidbox:

- Import FHIR Questionnaire description and create from (see `init-aidbox` service).
- Create Kafka topic for QuestionnaireResponse-s (see `init-kafka` service).

## STEP 2: Set up Subscription and Destination

### Create AidboxSubscriptionTopic resource
Expand Down Expand Up @@ -63,6 +96,11 @@ content-type: application/json
accept: application/json

{
"meta": {
"profile": [
"http://fhir.aidbox.app/StructureDefinition/TopicDestinationKafka"
]
},
"kind": "kafka",
"id": "kafka-destination",
"topic": "http://example.org/FHIR/R5/SubscriptionTopic/QuestionnaireResponse-topic",
Expand All @@ -80,7 +118,7 @@ accept: application/json
```

### Create Kafka Topic

Create a Kafka Topic named aidbox-forms. If you used our Docker Compose file, the Kafka topic should be created automatically.

## STEP 3: Feature demonstration
Expand All @@ -97,9 +135,6 @@ Open back Aidbox [REST Console](http://localhost:8888/ui/console#/rest) and get
GET /fhir/TopicDestination/kafka-destination/$status
```

### See messages in Kafka UI
### See messages in Kafka UI

Open [Kafka UI](http://localhost:8080/) -> `Topics` -> `aidbox-forms` -> `messages` and review the QuestionnaireResponse that was created after submitting the depression form.



49 changes: 28 additions & 21 deletions subscriptions/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
version: '3.8'

services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
container_name: zookeeper
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- "2181:2181"

kafka:
image: confluentinc/cp-kafka:latest
container_name: kafka
image: apache/kafka:latest
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: 'CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT'
KAFKA_ADVERTISED_LISTENERS: 'PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092'
KAFKA_LISTENERS: 'PLAINTEXT://kafka:29092,CONTROLLER://kafka:29093,PLAINTEXT_HOST://0.0.0.0:9092'
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_LISTENERS: LISTENER_INSIDE://0.0.0.0:29092, LISTENER_OUTSIDE://0.0.0.0:9092, CONTROLLER://0.0.0.0:29093
KAFKA_ADVERTISED_LISTENERS: LISTENER_INSIDE://kafka:29092, LISTENER_OUTSIDE://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_INSIDE:PLAINTEXT, LISTENER_OUTSIDE:PLAINTEXT, CONTROLLER:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_INSIDE
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:29093
ports:
- "9092:9092"
depends_on:
- zookeeper

- "9093:29093"
volumes:
- ./kafka-data:/var/lib/kafka/data

kafka-ui:
container_name: kafka-ui
image: provectuslabs/kafka-ui:latest
ports:
- 8080:8080
- "8080:8080"
depends_on:
- kafka
environment:
Expand All @@ -50,3 +43,17 @@ services:
echo -e 'Created the following topics:'
kafka-topics --bootstrap-server kafka:29092 --list
"
# init-aidbox:
# image: confluentinc/cp-kafka:latest
# depends_on:
# - kafka
# entrypoint: [ '/bin/sh', '-c' ]
# command: |
# "
# kafka-topics --bootstrap-server kafka:29092 --list
# echo -e 'Creating kafka topics'
# kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic aidbox-forms --replication-factor 1 --partitions 1
# echo -e 'Created the following topics:'
# kafka-topics --bootstrap-server kafka:29092 --list
# "

0 comments on commit 86252fa

Please sign in to comment.