Kafka additional SSL-authenticated producer client code example
Package Com.kafka.safe.ssl;
Import Org.apache.kafka.clients.producer.KafkaProducer;
Import Org.apache.kafka.clients.producer.Producer;
Import Org.apache.kafka.clients.producer.ProducerRecord;
Import org.apache.kafka.common.*;
Import java.util.*;
Import java.util.concurrent.Executors;
Import Java.util.concurrent.ScheduledExecutorService;
Import Java.util.concurrent.TimeUnit;
public class Sslproducertest {
public static final String topic_name = "Kafka-cluster";
public static final String topic_name = "Bpu_gateway_router";
private static final String CONTENT = "1704197100,9800100,4321,192.168.76.202,iaucap,2017-06-28 13:33:32";
public static void Main (string] args) throws Kafkaexception
{
Properties Props = new properties ();
Props.put ("Bootstrap.servers", "192.168.76.202:9093");
Props.put ("ACKs", "all");
Props.put ("Key.serializer", "Org.apache.kafka.common.serialization.StringSerializer");
Props.put ("Value.serializer", "Org.apache.kafka.common.serialization.StringSerializer");
Props.put ("Security.protocol", "SSL");
Props.put ("Ssl.truststore.location", "E:\\kafka\\safe\\client.truststore.jks");
Props.put ("Ssl.truststore.password", "test1234");
Props.put ("Ssl.keystore.location", "E:\\kafka\\safe\\client.keystore.jks");
Props.put ("Ssl.keystore.password", "pdas202");
Props.put ("Ssl.key.password", "pdas202");
Producer Producer = new Kafkaproducer (props);
Runnable Runnable = new Runnable ()
{
Integer times = 0;
public void Run ()
{
Producer.send (New Producerrecord (topic_name,integer.tostring), CONTENT);
}
};
Scheduledexecutorservice service = Executors.newsinglethreadscheduledexecutor ();
Service.scheduleatfixedrate (runnable, 0,100,timeunit.microseconds);
System.out.println ("-----------------");
}
}