KafkaClientsFunctions
The KafkaClients
class contains
functions for interacting with Kafka, such as creating Kafka producers and
sending messages to a topic. Below is a snippet showing how to use KafkaClientsFunctions
' instance
extension functions:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | // Producer configuration
def configs = [
'retries': 0,
'batch.size': 25,
'linger.ms': 500L,
'enable.idempotence': true
] as Properties
// Creates a Kafka producer
def producer = "localhost:9092,localhost:9093".createProducer("INTEGER", "STRING", configs)
// Publishes message to 'stocks' topic
producer.send("stocks", 42, "GOOGL")
// Closes the producer to avoid resource leaks
producer.close()
|