Kafka a code instance that the client does not encrypt
Package com.kafka.safe.none;
Import Org.apache.kafka.clients.producer.KafkaProducer;
Import Org.apache.kafka.clients.producer.Producer;
Import Org.apache.kafka.clients.producer.ProducerRecord;
Import Java.util.Date;
Import java.util.concurrent.Executors;
Import Java.util.concurrent.ScheduledExecutorService;
Import Java.util.concurrent.TimeUnit;
Import Java.text.SimpleDateFormat;
Import java.util.*;
public class Kafkaproducertest
{
public static final String topic_name = "Bpu_sensor_router";
private static String CONTENT = "1704197100,9800100,4321,192.168.76.202,iaucap,2017-06-28 13:33:32";
public static void Main (string] args) {
String brokerlist= "192.168.76.202:9092";
Properties Props = new properties ();
Props.put ("Bootstrap.servers", brokerlist);
Props.put ("Key.serializer", "Org.apache.kafka.common.serialization.StringSerializer");
Props.put ("Value.serializer", "Org.apache.kafka.common.serialization.StringSerializer");
Producer Producer = new Kafkaproducer (props);
Runnable Runnable = new Runnable ()
{
Integer times = 0;
public void Run ()
{
times++;
Producer.send (New Producerrecord (topic_name,integer.tostring), CONTENT);
System.out.println (times);
}
};
Scheduledexecutorservice service = Executors.newsinglethreadscheduledexecutor ();
Service.scheduleatfixedrate (runnable, 0,100,timeunit.microseconds);
System.out.println ("-----------------");
}
}