KafkaTopic API#
You can obtain a KafkaApi handle via Project.get_kafka_api. Once you have it, you can manage Kafka topics using the KafkaApi methods:
get_default_config #
Get the configuration to set up a Producer or Consumer for a Kafka broker using confluent-kafka.
import hopsworks
project = hopsworks.login()
kafka_api = project.get_kafka_api()
kafka_conf = kafka_api.get_default_config()
from confluent_kafka import Producer
producer = Producer(kafka_conf)
| RETURNS | DESCRIPTION |
|---|---|
dict | The kafka configuration. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
create_topic #
create_topic(
name: str,
schema: str,
schema_version: int,
replicas: int = 1,
partitions: int = 1,
) -> kafka_topic.KafkaTopic
Create a new kafka topic.
import hopsworks
project = hopsworks.login()
kafka_api = project.get_kafka_api()
kafka_topic = kafka_api.create_topic("my_topic", "my_schema", 1)
| PARAMETER | DESCRIPTION |
|---|---|
name | Name of the topic. TYPE: |
schema | Subject name of the schema. TYPE: |
schema_version | Version of the schema. TYPE: |
replicas | Replication factor for the topic. TYPE: |
partitions | Number of partitions for the topic. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
kafka_topic.KafkaTopic | The KafkaTopic object. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
get_topic #
get_topic(name: str) -> kafka_topic.KafkaTopic | None
Get kafka topic by name.
| PARAMETER | DESCRIPTION |
|---|---|
name | Name of the topic. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
kafka_topic.KafkaTopic | None | The KafkaTopic object or |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
get_topics #
get_topics() -> list[kafka_topic.KafkaTopic]
Get all kafka topics.
| RETURNS | DESCRIPTION |
|---|---|
list[kafka_topic.KafkaTopic] | List of KafkaTopic objects. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |