ApacheKafkaBroker
fastkafka.testing.ApacheKafkaBroker​
View sourceApacheKafkaBroker class, used for running unique kafka brokers in tests to prevent topic clashing.
init​
View source__init__(
self,
topics=[],
retries=3,
apply_nest_asyncio=False,
zookeeper_port=2181,
listener_port=9092,
)
Initialises the ApacheKafkaBroker object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topics | Iterable[str] | List of topics to create after sucessfull Kafka broker startup | [] |
retries | int | Number of retries to create kafka and zookeeper services using random | 3 |
apply_nest_asyncio | bool | set to True if running in notebook | False |
zookeeper_port | int | Port for clients (Kafka brokes) to connect | 2181 |
listener_port | int | Port on which the clients (producers and consumers) can connect | 9092 |
get_service_config_string​
View sourceget_service_config_string(
self, service, data_dir
)
Gets the configuration string for a service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service | str | Name of the service ("kafka" or "zookeeper"). | required |
data_dir | Path | Path to the directory where the service will save data. | required |
Returns:
Type | Description |
---|---|
str | The service configuration string. |
is_started​
View source@property
is_started(
self
)
Property indicating whether the ApacheKafkaBroker object is started.
The is_started property indicates if the ApacheKafkaBroker object is currently in a started state. This implies that Zookeeper and Kafka broker processes have sucesfully started and are ready for handling events.
Returns:
Type | Description |
---|---|
bool | True if the object is started, False otherwise. |
start​
View sourcestart(
self
)
Starts a local Kafka broker and ZooKeeper instance synchronously.
Returns:
Type | Description |
---|---|
str | The Kafka broker bootstrap server address in string format: host:port. |
stop​
View sourcestop(
self
)
Stops a local kafka broker and zookeeper instance synchronously