Classes

The following classes are available globally.

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

    let config = KafkaConfig()
    config.groupId = "Kitura"
    let producer = try? KafkaConsumer(config: config)
    
    See more

    Declaration

    Swift

    public class KafkaConfig
  • A KafkaClient for consuming messages on a topic from a broker.

    Usage Example:

    do {
        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)")
    }
    
    See more

    Declaration

    Swift

    public class KafkaConsumer: KafkaClient
  • A threadsafe KafkaClient for producing messages to a topic on a broker.

    Usage Example:

    do {
        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)")
    }
    
    See more

    Declaration

    Swift

    public class KafkaProducer: KafkaClient