Last month was full of important moments

Last month or so was really excited and full of different and important moments.

First of all, I become a father, my son was born 12 May, he is just amazing.

What else, well there was a chain of conferences/meetups I was speaking at and here are some links :

Sample #Kafka producer with #Groovy

Here is a brief example of Kafka producer client written in Groovy:

import org.apache.kafka.clients.producer.Callback
import org.apache.kafka.clients.producer.KafkaProducer
import org.apache.kafka.clients.producer.ProducerRecord
import org.apache.kafka.clients.producer.RecordMetadata
 
@Grab(group = "org.apache.kafka", module = "kafka-clients", version = "0.8.2.0")
@Grab(group = 'ch.qos.logback', module = 'logback-classic', version = '1.1.2')
 
Properties props = new Properties()
props.put('zk.connect', '192.168.56.71:2181')
props.put('bootstrap.servers', '192.168.56.71:9092,192.168.56.71:9093,192.168.56.71:9094')
props.put('key.serializer', 'org.apache.kafka.common.serialization.StringSerializer')
props.put('value.serializer', 'org.apache.kafka.common.serialization.StringSerializer')
 
def producer = new KafkaProducer(props)
 
def messageSender = { String topic, String message ->
    String key = new Random().nextLong()
    String compoundMessage = "key: $key, message: $message"
    producer.send(
            new ProducerRecord<String, String>(topic, key, compoundMessage),
            { RecordMetadata metadata, Exception e ->
                println "The offset of the record we just sent is: ${metadata.offset()}"
            } as Callback
    )
}
args.each { arg ->
    println "sending message $arg"
    messageSender('simple.topic', arg)
}
producer.close()

In order to run it use:

groovy -Dgroovy.grape.report.downloads=true producer.groovy hello from Groovy client