Sample code for testing Kafka
mvn eclipse:eclipse
mvn clean compile package
./bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic test101 --partitions 1 --replication-factor 1
bin/kafka-console-producer.sh --broker-list `hostname -f`:6667 --topic test101
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test101
bootstrap.servers=<your broker service host>:<your broker service port>
./run_publisher.sh <input.properties>
./run_Consumer.sh <input.properties>
For you running in Kerberos environment, you need to create a principal for the client application. For the principal create a keytab
sudo su - kafka
kinit kafka
bin/kafka-topics.sh --zookeeper `hostname -f`:2181 --create --topic test101 --partitions 1 --replication-factor 1
kinit <user principal>
bin/kafka-console-producer.sh --broker-list `hostname -f`:6667 --topic test101 --security-protocol PLAINTEXTSASL
kinit <user principal> (if different user)
bin/kafka-console-consumer.sh --zookeeper `hostname -f`:2181 --topic test101 --security-protocol PLAINTEXTSASL --from-beginning
--consumer.config /tmp/consumer.properties --delete-consumer-offsets
KafkaClient {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
storeKey=true
keyTab="jane.keytab"
principal="jane@EXAMPLE.COM";
};
./run_publisher_kerberos.sh input.properties kafka_client_jaas.conf
./run_consumer_kerberos.sh input.properties kafka_client_jaas.conf