Classes
The following classes are available globally.
-
A class for clients that will connect to a Kafka server.
See more
This can either be aKafkaConsumer
or aKafkaProducer
.Declaration
Swift
public class KafkaClient
-
The configuration settings for a Kafka consumer/producer. These can be set either using the helper functions provided or by subscripting
KafkaConfig
with the configuration key.
Link to configuration keys and descriptions.Usage Example:
See morelet config = KafkaConfig() config.groupId = "Kitura" let producer = try? KafkaConsumer(config: config)
Declaration
Swift
public class KafkaConfig
-
A
KafkaClient
for consuming messages on a topic from a broker.Usage Example:
See moredo { let config = KafkaConfig() config.groupId = "Kitura" config.autoOffsetReset = .beginning let consumer = try KafkaConsumer(config: config) consumer.connect(brokers: "localhost:9092") try consumer.subscribe(topics: ["test"]) let records = consumer.poll() print(records) } catch { print("Error creating consumer: \(error)") }
Declaration
Swift
public class KafkaConsumer: KafkaClient
-
A threadsafe
KafkaClient
for producing messages to a topic on a broker.Usage Example:
See moredo { let producer = try KafkaProducer() producer.connect(brokers: "localhost:9092") producer.send(producerRecord: KafkaProducerRecord(topic: "test", value: "Hello World")) { result in switch result { case .success(let message): print("Message at offset \(message.offset) successfully sent") case .failure(let error): print("Error producing: \(error)") } } } catch { print("Error creating producer: \(error)") }
Declaration
Swift
public class KafkaProducer: KafkaClient