Skip to main content
Version: 0.8.0

ApacheKafkaBroker

fastkafka.testing.ApacheKafkaBroker​

View source

ApacheKafkaBroker 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:

NameTypeDescriptionDefault
topicsIterable[str]List of topics to create after sucessfull Kafka broker startup[]
retriesintNumber of retries to create kafka and zookeeper services using random3
apply_nest_asyncioboolset to True if running in notebookFalse
zookeeper_portintPort for clients (Kafka brokes) to connect2181
listener_portintPort on which the clients (producers and consumers) can connect9092

get_service_config_string​

View source
get_service_config_string(
self, service, data_dir
)

Gets the configuration string for a service.

Parameters:

NameTypeDescriptionDefault
servicestrName of the service ("kafka" or "zookeeper").required
data_dirPathPath to the directory where the service will save data.required

Returns:

TypeDescription
strThe 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:

TypeDescription
boolTrue if the object is started, False otherwise.

start​

View source
start(
self
)

Starts a local Kafka broker and ZooKeeper instance synchronously.

Returns:

TypeDescription
strThe Kafka broker bootstrap server address in string format: host:port.

stop​

View source
stop(
self
)

Stops a local kafka broker and zookeeper instance synchronously