-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4640cfe
commit 62f0ee7
Showing
8 changed files
with
72 additions
and
4 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
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,27 @@ | ||
--- | ||
# 0.5 - API | ||
# 2 - Release | ||
# 3 - Contributing | ||
# 5 - Template Page | ||
# 10 - Default | ||
search: | ||
boost: 10 | ||
--- | ||
|
||
# Passing Additional Configuration to confluent-kafka-python | ||
|
||
The `confluent-kafka-python` package is a Python wrapper around [librdkakfa](https://github.com/confluentinc/librdkafka), which is a C/C++ client library for Apache Kafka. | ||
|
||
`confluent-kafka-python` accepts a `config` dictionary that is then passed on to `librdkafka`. `librdkafka` provides plenty of [configuration properties](https://github.com/confluentinc/librdkafka/blob/master/CONFIGURATION.md) to configure the Kafka client. | ||
|
||
**FastStream** also provides users with the ability to pass the config dictionary to `librdkafka` to provide greater customizability. | ||
|
||
## Example | ||
|
||
In the following example, we are setting the parameter `topic.metadata.refresh.fast.interval.ms`'s value to `300` instead of the default value `100` via the `config` parameter. | ||
|
||
```python linenums="1" hl_lines="15 16" | ||
{! docs_src/confluent/additional_config/app.py !} | ||
``` | ||
|
||
Similarly, you could use the `config` parameter to pass any [configuration properties](https://github.com/confluentinc/librdkafka/blob/master/CONFIGURATION.md) to `librdkafka`. |
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
Empty file.
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,22 @@ | ||
from pydantic import BaseModel, Field | ||
|
||
from faststream import FastStream, Logger | ||
from faststream.confluent import KafkaBroker | ||
|
||
|
||
class HelloWorld(BaseModel): | ||
msg: str = Field( | ||
..., | ||
examples=["Hello"], | ||
description="Demo hello world message", | ||
) | ||
|
||
|
||
config = {"topic.metadata.refresh.fast.interval.ms": 300} | ||
broker = KafkaBroker("localhost:9092", config=config) | ||
app = FastStream(broker) | ||
|
||
|
||
@broker.subscriber("hello_world") | ||
async def on_hello_world(msg: HelloWorld, logger: Logger): | ||
logger.info(msg) |
Empty file.
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,15 @@ | ||
import pytest | ||
|
||
from docs.docs_src.confluent.additional_config.app import ( | ||
HelloWorld, | ||
broker, | ||
on_hello_world, | ||
) | ||
from faststream.confluent import TestKafkaBroker | ||
|
||
|
||
@pytest.mark.asyncio() | ||
async def test_base_app(): | ||
async with TestKafkaBroker(broker): | ||
await broker.publish(HelloWorld(msg="First Hello"), "hello_world") | ||
on_hello_world.mock.assert_called_with(dict(HelloWorld(msg="First Hello"))) |