-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate consume multiple topics example to a proper project st…
…ructure (#145)
- Loading branch information
1 parent
3128ffd
commit 66b68df
Showing
5 changed files
with
114 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Consume Multiple Topics Example | ||
|
||
Consume multiple topics example with `kstreams` | ||
|
||
## Requirements | ||
|
||
python 3.8+, poetry, docker-compose | ||
|
||
### Installation | ||
|
||
```bash | ||
poetry install | ||
``` | ||
|
||
## Usage | ||
|
||
1. Start the kafka cluster: From `kstreams` project root execute `./scripts/cluster/start` | ||
2. Inside this folder execute `poetry run app` | ||
|
||
The app should publish 5 events with the same payload (i.e. `'{"message": "Hello world from topic {topic}!"}'`) to two topics: `local--kstreams-2` and `local--hello-world`. | ||
The `ConsumerRecord` will then be consumed and printed by the consumer. | ||
|
||
You should see something similar to the following logs: | ||
|
||
```bash | ||
❯ me@me-pc simple-example % poetry run app | ||
Topic local--kstreams-2 is not available during auto-create initialization | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Topic local--kstreams-2 is not available during auto-create initialization | ||
Topic local--kstreams-2 is not available during auto-create initialization | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Message sent: RecordMetadata(topic='local--kstreams-2', partition=0, topic_partition=TopicPartition(topic='local--kstreams-2', partition=0), offset=0, timestamp=1703694932136, timestamp_type=0, log_start_offset=0) | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Message sent: RecordMetadata(topic='local--hello-world', partition=0, topic_partition=TopicPartition(topic='local--hello-world', partition=0), offset=0, timestamp=1703694934271, timestamp_type=0, log_start_offset=0) | ||
Group Coordinator Request failed: [Error 15] GroupCoordinatorNotAvailableError | ||
Message sent: RecordMetadata(topic='local--kstreams-2', partition=0, topic_partition=TopicPartition(topic='local--kstreams-2', partition=0), offset=1, timestamp=1703694935284, timestamp_type=0, log_start_offset=0) | ||
Event consumed from topic: local--kstreams-2, headers: (), payload: b'{"message": "Hello world from topic local--kstreams-2!"}' | ||
Message sent: RecordMetadata(topic='local--hello-world', partition=0, topic_partition=TopicPartition(topic='local--hello-world', partition=0), offset=1, timestamp=1703694936320, timestamp_type=0, log_start_offset=0) | ||
Event consumed from topic: local--hello-world, headers: (), payload: b'{"message": "Hello world from topic local--hello-world!"}' | ||
Message sent: RecordMetadata(topic='local--kstreams-2', partition=0, topic_partition=TopicPartition(topic='local--kstreams-2', partition=0), offset=2, timestamp=1703694937336, timestamp_type=0, log_start_offset=0) | ||
Event consumed from topic: local--kstreams-2, headers: (), payload: b'{"message": "Hello world from topic local--kstreams-2!"}' | ||
Message sent: RecordMetadata(topic='local--hello-world', partition=0, topic_partition=TopicPartition(topic='local--hello-world', partition=0), offset=2, timestamp=1703694938349, timestamp_type=0, log_start_offset=0) | ||
Event consumed from topic: local--hello-world, headers: (), payload: b'{"message": "Hello world from topic local--hello-world!"}' | ||
Message sent: RecordMetadata(topic='local--kstreams-2', partition=0, topic_partition=TopicPartition(topic='local--kstreams-2', partition=0), offset=3, timestamp=1703694939361, timestamp_type=0, log_start_offset=0) | ||
Event consumed from topic: local--kstreams-2, headers: (), payload: b'{"message": "Hello world from topic local--kstreams-2!"}' | ||
Message sent: RecordMetadata(topic='local--hello-world', partition=0, topic_partition=TopicPartition(topic='local--hello-world', partition=0), offset=3, timestamp=1703694940376, timestamp_type=0, log_start_offset=0) | ||
Event consumed from topic: local--hello-world, headers: (), payload: b'{"message": "Hello world from topic local--hello-world!"}' | ||
Message sent: RecordMetadata(topic='local--kstreams-2', partition=0, topic_partition=TopicPartition(topic='local--kstreams-2', partition=0), offset=4, timestamp=1703694941386, timestamp_type=0, log_start_offset=0) | ||
Event consumed from topic: local--kstreams-2, headers: (), payload: b'{"message": "Hello world from topic local--kstreams-2!"}' | ||
Message sent: RecordMetadata(topic='local--hello-world', partition=0, topic_partition=TopicPartition(topic='local--hello-world', partition=0), offset=4, timestamp=1703694942404, timestamp_type=0, log_start_offset=0) | ||
Event consumed from topic: local--hello-world, headers: (), payload: b'{"message": "Hello world from topic local--hello-world!"} | ||
``` | ||
## Note | ||
If you plan on using this example, pay attention to the `pyproject.toml` dependencies, where | ||
`kstreams` is pointing to the parent folder. You will have to set the latest version. |
1 change: 1 addition & 0 deletions
1
examples/consume-multiple-topics-example/consume_multiple_topics_example/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[tool.poetry] | ||
name = "consume-multiple-topics-example" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["Marcos Schroh <[email protected]>, Santiago Fraire <[email protected]>, Alexandre Cirilo <[email protected]>"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.8" | ||
aiorun = "^2022.4.1" | ||
kstreams = { path = "../../.", develop = true } | ||
|
||
[tool.poetry.dev-dependencies] | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
|
||
[tool.poetry.scripts] | ||
app = "consume_multiple_topics_example.app:main" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters