Skip to content

Commit

Permalink
add AidboxSubscriptionTopic tutorial
Browse files Browse the repository at this point in the history
Co-authored-by: @aleksandr.penskoi <[email protected]>
  • Loading branch information
Rost-is-love and ryukzak committed Aug 26, 2024
1 parent 5b078e5 commit 5f7d1ea
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 11 deletions.
99 changes: 89 additions & 10 deletions subscriptions/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,105 @@
# [WIP] Dynamic SubscriptionTopic with destinations
# [WIP] Aidbox SubscriptionTopic with Kafka

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

## Prerequisites

- [Docker](https://www.docker.com/)

## STEP 1: Run Kafka and Kafka UI
## Step 1: Set Up the Environment

### Set Up Aidbox

Copy the `.env.tpl` file to `.env`:

```shell
docker compose up
cp .env.tpl .env
```

If you are hosting Aidbox on your local machine, obtain the self-hosted license from the [Aidbox Portal](https://aidbox.app/).

Add the license key (AIDBOX_LICENSE) to the .env file.

### Run Aidbox, Kafka & Kafka UI

```shell
docker compose up
```

- Aidbox will be available on <http://localhost:8888/>
- Username: `admin`
- Password: `password`
- Kafka UI will be available on <http://localhost:8080/>
- Kafka will be available on `http://localhost:9092/`

## STEP 2: Set up Subscription and Destination

### Create AidboxSubscriptionTopic resource

To create Subscription on QuestionnaireResponse resource open API's -> REST Console and execute the following request:

```json
POST /fhir/AidboxSubscriptionTopic
content-type: application/json
accept: application/json

{
"resourceType": "AidboxSubscriptionTopic",
"url": "http://example.org/FHIR/R5/SubscriptionTopic/QuestionnaireResponse-topic",
"status": "active",
"trigger": [
{
"resource": "QuestionnaireResponse"
}
]
}
```

## STEP 2: Open Kafka UI
### Create TopicDestination resource

```json
POST /fhir/TopicDestination
content-type: application/json
accept: application/json

{
"kind": "kafka",
"id": "kafka-destination",
"topic": "http://example.org/FHIR/R5/SubscriptionTopic/QuestionnaireResponse-topic",
"parameter": [
{
"name": "kafkaTopic",
"valueString": "aidbox-forms"
},
{
"name": "bootstrap.servers",
"valueString": "localhost:9092"
}
]
}
```

### 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

Kafka UI available on `http://localhost:8080/`
### Submit form

Open [Depression form](http://localhost:8888/ui/sdc#/questionnaire-response/depression-form), fill it out, and submit it.

### Check TopicDestination status

Open back Aidbox [REST Console](http://localhost:8888/ui/console#/rest) and get the TopicDestination status:

```
GET /fhir/TopicDestination/kafka-destination/$status
```

## STEP 3: Create Kafka Topic
### See messages in Kafka UI

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

## STEP 4: Trigger Aidbox Subscription

## Step 5: See messages

2 changes: 1 addition & 1 deletion subscriptions/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ services:
"
kafka-topics --bootstrap-server kafka:29092 --list
echo -e 'Creating kafka topics'
kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic my-topic --replication-factor 1 --partitions 1
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 5f7d1ea

Please sign in to comment.