Java access to Kerberos certified Kafka

Source: Internet
Author: User

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Projectxmlns= "http://maven.apache.org/POM/4.0.0"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">5     <modelversion>4.0.0</modelversion>6 7     <groupId>Com.ht</groupId>8     <Artifactid>Kafkatest</Artifactid>9     <version>1.0-snapshot</version>Ten     <Build> One         <Plugins> A             <plugin> -                 <groupId>Org.apache.maven.plugins</groupId> -                 <Artifactid>Maven-compiler-plugin</Artifactid> the                 <Configuration> -                     <Source>1.7</Source> -                     <Target>1.7</Target> -                 </Configuration> +             </plugin> -         </Plugins> +     </Build> A  at  -     <Dependencies> -         <Dependency> -             <groupId>Org.apache.kafka</groupId> -             <Artifactid>Kafka-clients</Artifactid> -             <version>0.10.0.0</version> in         </Dependency> -     </Dependencies> to </Project>

Java code

1 ImportOrg.apache.kafka.clients.CommonClientConfigs;2 ImportOrg.apache.kafka.clients.consumer.ConsumerRecord;3 Importorg.apache.kafka.clients.consumer.ConsumerRecords;4 ImportOrg.apache.kafka.clients.consumer.KafkaConsumer;5 6 Importjava.util.Collections;7 Importjava.util.Properties;8 9 Import Staticorg.apache.kafka.clients.consumer.consumerconfig.*;Ten  One /** A  * @authorSunzq -  * @since2017/8/29 -  */ the  Public classApplication { -      Public Static voidMain (string[] args) { -  -Properties props =NewProperties (); +Props.put (Bootstrap_servers_config, "node1:6667,node2:6667,node3:6667,node4:6667"); -Props.put (Enable_auto_commit_config, "true"); +Props.put (Group_id_config, "test08291103"); A //props.put (Consumerconfig.client_id_config, "test0829"); atProps.put (Auto_commit_interval_ms_config, 1000); -Props.put (Auto_offset_reset_config, "earliest"); -Props.put (Key_deserializer_class_config, "Org.apache.kafka.common.serialization.StringDeserializer"); -Props.put (Value_deserializer_class_config, "Org.apache.kafka.common.serialization.StringDeserializer"); -Props.put (Commonclientconfigs.security_protocol_config, "Sasl_plaintext"); -  inkafkaconsumer<string, string> consumer =NewKafkaconsumer<>(props); -         //Topic Name:test9 toConsumer.subscribe (Collections.singleton ("Test9")); +          while(true) { -Consumerrecords<string, string> records = Consumer.poll (100); the              for(Consumerrecord<string, string>record:records) *System.out.printf ("offset =%d, key =%s, value =%s%n", Record.offset (), Record.key (), Record.value ()); $         }Panax Notoginseng     } -}

Startup parameters

-djava.security.krb5.conf=c:\\app\\conf\\krb5.conf-djava.security.auth. login. config=c:\\app\\conf\\kafka_jaas.conf

Under Windows, remember to use \ \

Java access to Kerberos certified Kafka

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.