Kafka a code instance that the client does not encrypt

Source: Internet
Author: User
Keywords No encryption code
Tags apache client clients code import java package public

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

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.