|
| 1 | +# Sample Project: Confluent Images |
| 2 | +This sample project shows how to use the [QuestDB Kafka connector](https://questdb.io/docs/third-party-tools/kafka/questdb-kafka/) together with Confluent Docker images for Kafka. |
| 3 | +The sample uses the [Confluent CP Kafka Connect](https://hub.docker.com/r/confluentinc/cp-kafka-connect-base) as a base for |
| 4 | +building a custom Docker image with the QuestDB Kafka connector installed. The QuestDB Kafka connector is installed from the |
| 5 | +[Confluent Hub](https://www.confluent.io/hub/questdb/kafka-questdb-connector). |
| 6 | + |
| 7 | + |
| 8 | +It also uses the [Kafka UI](https://github.com/provectus/kafka-ui) project for Kafka administration. |
| 9 | + |
| 10 | +## Prerequisites: |
| 11 | +- Git |
| 12 | +- Working Docker environment, including docker-compose |
| 13 | +- Internet access to download dependencies |
| 14 | + |
| 15 | +## Usage: |
| 16 | +- Clone this repository via `git clone https://github.com/questdb/kafka-questdb-connector.git` |
| 17 | +- `cd kafka-questdb-connector/kafka-questdb-connector-samples/confluent-docker-images` to enter the directory with this sample. |
| 18 | +- Run `docker compose build` to build a docker image with the sample project. |
| 19 | +- Run `docker compose up` to start the node.js producer, Apache Kafka and QuestDB containers. |
| 20 | +- The previous command will generate a lot of log messages. Eventually logging should cease. This means both Apache Kafka and QuestDB are running. |
| 21 | +- Go to http://localhost:8080/ui/clusters/kafka/connectors and click on the “Create Connector” button. |
| 22 | +  |
| 23 | +- The connector name should be QuestDB, use the following configuration and click at Submit: |
| 24 | + ```json |
| 25 | + { |
| 26 | + "connector.class": "io.questdb.kafka.QuestDBSinkConnector", |
| 27 | + "topics": "Orders", |
| 28 | + "host": "questdb:9009", |
| 29 | + "name": "questdb", |
| 30 | + "value.converter": "org.apache.kafka.connect.json.JsonConverter", |
| 31 | + "include.key": false, |
| 32 | + "key.converter": "org.apache.kafka.connect.storage.StringConverter", |
| 33 | + "table": "orders_table", |
| 34 | + "value.converter.schemas.enable": false |
| 35 | + } |
| 36 | + ``` |
| 37 | +- Go to http://localhost:8080/ui/clusters/kafka/all-topics/Orders and click on the “Produce Message” button. If the Topic is not created yet then try to refresh the page. |
| 38 | +- Use the following JSON as value, keep the rest of the fields as default and click at “Produce Message”: |
| 39 | + ```json |
| 40 | + {"firstname": "Arthur", "lastname": "Dent", "age": 42} |
| 41 | + ``` |
| 42 | +- Go to [QuestDB web console](http://localhost:9000) and run the following query: |
| 43 | + ```sql |
| 44 | + select * from orders_table |
| 45 | + ``` |
| 46 | +- You should see a result similar to this: |
| 47 | +  |
| 48 | + |
| 49 | +## How it works |
| 50 | +The Docker Compose file starts the following containers: |
| 51 | +- Kafka broker - the message broker |
| 52 | +- Zookeeper - the coordination service for Kafka |
| 53 | +- Kafka Connect - the framework for running Kafka connectors |
| 54 | +- QuestDB - the fastest open-source time-series database |
| 55 | +- Kafka UI - the web UI for Kafka administration |
| 56 | + |
| 57 | +The Kafka Connect container is built from the [Confluent CP Kafka Connect](https://hub.docker.com/r/confluentinc/cp-kafka-connect-base) by image by using the following Dockerfile: |
| 58 | +```dockerfile |
| 59 | +FROM confluentinc/cp-kafka-connect-base:7.3.2 |
| 60 | +RUN confluent-hub install --no-prompt questdb/kafka-questdb-connector:0.6 |
| 61 | +``` |
| 62 | +The `confluent-hub` command installs the QuestDB Kafka connector from the [Confluent Hub](https://www.confluent.io/hub/questdb/kafka-questdb-connector). |
| 63 | + |
| 64 | +When all containers are running then we use the Kafka UI to start the QuestDB connector. The connector is configured to read data from a Kafka topic `Orders` and write it to the QuestDB table `orders_table`. |
| 65 | + |
| 66 | +Then we use the Kafka UI to produce a message to the `Orders` topic. The message is a JSON document with the following structure: |
| 67 | +```json |
| 68 | +{"firstname": "Arthur", "lastname": "Dent", "age": 42} |
| 69 | +``` |
| 70 | +The Kafka Connect container receives the message and writes it to the QuestDB table. |
| 71 | + |
| 72 | +Finally, we use the QuestDB web console to query the table and see the result! |
| 73 | + |
| 74 | +## Further reading |
| 75 | +- [QuestDB Kafka connector](https://questdb.io/docs/third-party-tools/kafka/questdb-kafka/) |
| 76 | + |
| 77 | +## Bugs and Feedback |
| 78 | +For bugs, questions and discussions please use the [Github Issues](https://github.com/questdb/kafka-questdb-connector/issues/new) |
0 commit comments