providers
Kafka

Kafka

The kafka block declares a Kafka broker, using the confluentinc/cp-kafka image by default.

Producing messages

To declare a producer, use producer block, which emits messages periodically.

producer takes the following args:

ArgDescription
frequencyA Kotlin Duration (opens in a new tab) indicating how frequently the producer closure should be called.
topicThe topic to write to

The body is a function which returns a message to be written to Kafka

stack {
    kafka {
        producer("100ms".duration(), "stockQuotes") {
            jsonMessage {
                mapOf(
                    "symbol" to listOf("GBP/USD", "AUD/USD", "NZD/USD").random(),
                    "price" to Random.nextDouble(0.8, 0.95).toBigDecimal()
                )
            }
        }
    }
}

Returned values

When a kafka component is declared, the following data is returned:

KeyDescription
bootstrapServersThe bootstrap servers address of the started Kafka broker