Skip to content

Home

Development

IDEs

API Explorer

Releases

Release notes

Martini Runtime

Martini Desktop

Martini Online

Feature requests

Bug reports

KafkaClientsMethods

The KafkaClientsMethods class contains one-liners for interacting with Kafka, such as creating Kafka producers and sending messages to a topic. Below is a snippet showing how to use KafkaClientsMethods' instance extension methods:

Sample Gloop service showing how to use the `KafkaClientsMethods` one-liners

 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()