|
| 1 | +# Kstreams SSL example |
| 2 | + |
| 3 | +This example shows how setup an SSL connection with `kstreams`. For this purpose we have to setup a local kafka SSL cluster. |
| 4 | + |
| 5 | +`ENV` varialbles are exported using the script `/scripts/ssl/export-env-variables` and loaded in python using [pydantic-settings](https://docs.pydantic.dev/latest/concepts/pydantic_settings/). |
| 6 | + |
| 7 | +Check [resources.py](https://github.com/kpn/kstreams/blob/master/examples/ssl-example/ssl_example/resources.py) to see how the backend with `SSL` is created |
| 8 | + |
| 9 | +## Requirements |
| 10 | + |
| 11 | +`python 3.8+`, `poetry`, `docker-compose`, `openssl` |
| 12 | + |
| 13 | +### Usage |
| 14 | + |
| 15 | +First create the server and client sertificates: |
| 16 | + |
| 17 | +```bash |
| 18 | +./scripts/ssl/ssl-setup |
| 19 | +``` |
| 20 | + |
| 21 | +After executing the privious script, you will see a new folder called `kafka-certs`. The folder contains the `server` (inside the server folder), |
| 22 | +`admin` (inside the admin folder) and `client` certicicates. Do not worry about the content of them, it is just an example and they can be deleted, |
| 23 | +shared and recreated (it is just a local example) |
| 24 | + |
| 25 | +Now you can run the local SSL cluster: |
| 26 | + |
| 27 | +```bash |
| 28 | +./scripts/cluster/start |
| 29 | +``` |
| 30 | + |
| 31 | +Second, you need to install the project dependencies dependencies. In a different terminal execute: |
| 32 | + |
| 33 | +```bash |
| 34 | +poetry install |
| 35 | +``` |
| 36 | + |
| 37 | +Export the env variables: |
| 38 | + |
| 39 | +```bash |
| 40 | +. ./scripts/ssl/export-env-variables |
| 41 | +``` |
| 42 | + |
| 43 | +Then we can run the project |
| 44 | + |
| 45 | +```bash |
| 46 | +poetry run app |
| 47 | +``` |
| 48 | + |
| 49 | +You should see something similar to the following logs: |
| 50 | + |
| 51 | +```bash |
| 52 | +kstreams/examples/ssl-example via 🐳 colima is 📦 v0.1.0 via 🐍 v3.12.4 |
| 53 | +❯ poetry run app |
| 54 | + |
| 55 | +INFO:ssl_example.app:Starting application... |
| 56 | +INFO:aiokafka.consumer.subscription_state:Updating subscribed topics to: frozenset({'local--kstreams'}) |
| 57 | +INFO:aiokafka.consumer.consumer:Subscribed to topic(s): {'local--kstreams'} |
| 58 | +INFO:kstreams.prometheus.monitor:Starting Prometheus Monitoring started... |
| 59 | +INFO:ssl_example.app:Producing event 0 |
| 60 | +INFO:ssl_example.app:Producing event 1 |
| 61 | +INFO:ssl_example.app:Producing event 2 |
| 62 | +INFO:ssl_example.app:Producing event 3 |
| 63 | +INFO:ssl_example.app:Producing event 4 |
| 64 | +ERROR:aiokafka.consumer.group_coordinator:Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError |
| 65 | +ERROR:aiokafka.consumer.group_coordinator:Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError |
| 66 | +ERROR:aiokafka.consumer.group_coordinator:Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError |
| 67 | +ERROR:aiokafka.consumer.group_coordinator:Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError |
| 68 | +ERROR:aiokafka.consumer.group_coordinator:Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError |
| 69 | +ERROR:aiokafka.consumer.group_coordinator:Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError |
| 70 | +ERROR:aiokafka.consumer.group_coordinator:Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError |
| 71 | +ERROR:aiokafka.consumer.group_coordinator:Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError |
| 72 | +ERROR:aiokafka.consumer.group_coordinator:Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError |
| 73 | +ERROR:aiokafka.consumer.group_coordinator:Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError |
| 74 | +ERROR:aiokafka.consumer.group_coordinator:Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError |
| 75 | +ERROR:aiokafka.consumer.group_coordinator:Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError |
| 76 | +INFO:aiokafka.consumer.group_coordinator:Discovered coordinator 1 for group example-group |
| 77 | +INFO:aiokafka.consumer.group_coordinator:Revoking previously assigned partitions set() for group example-group |
| 78 | +INFO:aiokafka.consumer.group_coordinator:(Re-)joining group example-group |
| 79 | +INFO:aiokafka.consumer.group_coordinator:Joined group 'example-group' (generation 1) with member_id aiokafka-0.11.0-5fb10c73-64b2-42a8-ae8a-23f59d4a3b6b |
| 80 | +INFO:aiokafka.consumer.group_coordinator:Elected group leader -- performing partition assignments using roundrobin |
| 81 | +INFO:aiokafka.consumer.group_coordinator:Successfully synced group example-group with generation 1 |
| 82 | +INFO:aiokafka.consumer.group_coordinator:Setting newly assigned partitions {TopicPartition(topic='local--kstreams', partition=0)} for group example-group |
| 83 | +``` |
| 84 | + |
| 85 | +## Note |
| 86 | + |
| 87 | +If you plan on using this example, pay attention to the `pyproject.toml` dependencies, where |
| 88 | +`kstreams` is pointing to the parent folder. You will have to set the latest version. |
0 commit comments