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

The latest #SonarQube inside #Docker ready to check you #Java #code #quality

Here is my version of Docker container to run SonarQube with set of plugins to enable code quality analysis for Java based projects .

To use it you can pull Docker container:

docker pull webdizz/sonarqube-plugins:latest

There is also a Fig example to run SonarQube that you can check out from my Github repository https://github.com/webdizz/docker-sonarqube-plugins