Kafka additional SSL-authenticated producer client code example

Source: Internet
Author: User
Keywords SSL authentication
Tags apache authentication client clients code example import java

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

}

}

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.