Skip to content

Commit d413949

Browse files
authored
Merge pull request #115670 from hrasheed-msft/hdi_kafkaapis
HDInsight updating Kafka producer consumer API doc
2 parents 6c74e48 + d21ed82 commit d413949

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

articles/hdinsight/domain-joined/apache-domain-joined-run-kafka.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ms.author: hrasheed
66
ms.reviewer: jasonh
77
ms.service: hdinsight
88
ms.topic: tutorial
9-
ms.date: 09/04/2019
9+
ms.date: 05/19/2020
1010
---
1111

1212
# Tutorial: Configure Apache Kafka policies in HDInsight with Enterprise Security Package (Preview)
@@ -142,7 +142,8 @@ Based on the Ranger policies configured, **sales_user** can produce/consume topi
142142

143143
4. Follow Step 3 under **Build and deploy the example** in [Tutorial: Use the Apache Kafka Producer and Consumer APIs](../kafka/apache-kafka-producer-consumer-api.md#build-and-deploy-the-example) to ensure that the `kafka-producer-consumer.jar` is also available to **sales_user**.
144144

145-
**Note: For this tutorial, please use the kafka-producer-consumer.jar under "DomainJoined-Producer-Consumer" project (not the one under Producer-Consumer project, which is for non domain joined scenarios).**
145+
> [!NOTE]
146+
> For this tutorial, please use the kafka-producer-consumer.jar under "DomainJoined-Producer-Consumer" project (not the one under Producer-Consumer project, which is for non domain joined scenarios).
146147
147148
5. Verify that **sales_user1** can produce to topic `salesevents` by executing the following command:
148149

articles/hdinsight/kafka/apache-kafka-producer-consumer-api.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.reviewer: jasonh
77
ms.service: hdinsight
88
ms.custom: hdinsightactive
99
ms.topic: tutorial
10-
ms.date: 10/08/2019
10+
ms.date: 05/19/2020
1111
#Customer intent: As a developer, I need to create an application that uses the Kafka consumer/producer API with Kafka on HDInsight
1212
---
1313

@@ -69,7 +69,7 @@ The important things to understand in the `pom.xml` file are:
6969

7070
### Producer.java
7171

72-
The producer communicates with the Kafka broker hosts (worker nodes) and sends data to a Kafka topic. The following code snippet is from the [Producer.java](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started/blob/master/Producer-Consumer/src/main/java/com/microsoft/example/Producer.java) file from the [GitHub repository](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started) and shows how to set the producer properties:
72+
The producer communicates with the Kafka broker hosts (worker nodes) and sends data to a Kafka topic. The following code snippet is from the [Producer.java](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started/blob/master/Producer-Consumer/src/main/java/com/microsoft/example/Producer.java) file from the [GitHub repository](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started) and shows how to set the producer properties. For Enterprise Security Enabled clusters an additional property must be added "properties.setProperty(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SASL_PLAINTEXT");"
7373

7474
```java
7575
Properties properties = new Properties();
@@ -83,7 +83,7 @@ KafkaProducer<String, String> producer = new KafkaProducer<>(properties);
8383

8484
### Consumer.java
8585

86-
The consumer communicates with the Kafka broker hosts (worker nodes), and reads records in a loop. The following code snippet from the [Consumer.java](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started/blob/master/Producer-Consumer/src/main/java/com/microsoft/example/Consumer.java) file sets the consumer properties:
86+
The consumer communicates with the Kafka broker hosts (worker nodes), and reads records in a loop. The following code snippet from the [Consumer.java](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started/blob/master/Producer-Consumer/src/main/java/com/microsoft/example/Consumer.java) file sets the consumer properties. For Enterprise Security Enabled clusters an additional property must be added "properties.setProperty(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SASL_PLAINTEXT");"
8787

8888
```java
8989
KafkaConsumer<String, String> consumer;
@@ -111,6 +111,16 @@ The [Run.java](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started
111111

112112
## Build and deploy the example
113113

114+
### Use pre-built JAR files
115+
116+
Download the jars from the [Kafka Get Started Azure sample](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started/tree/master/Prebuilt-Jars). If your cluster is **Enterprise Security Package (ESP)** enabled, use kafka-producer-consumer-esp.jar. Use the command below to copy the jars to your cluster.
117+
118+
```cmd
119+
scp kafka-producer-consumer*.jar [email protected]:kafka-producer-consumer.jar
120+
```
121+
122+
### Build the JAR files from code
123+
114124
If you would like to skip this step, prebuilt jars can be downloaded from the `Prebuilt-Jars` subdirectory. Download the kafka-producer-consumer.jar. If your cluster is **Enterprise Security Package (ESP)** enabled, use kafka-producer-consumer-esp.jar. Execute step 3 to copy the jar to your HDInsight cluster.
115125

116126
1. Download and extract the examples from [https://github.com/Azure-Samples/hdinsight-kafka-java-get-started](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started).
@@ -121,12 +131,12 @@ If you would like to skip this step, prebuilt jars can be downloaded from the `P
121131
mvn clean package
122132
```
123133
124-
This command creates a directory named `target`, that contains a file named `kafka-producer-consumer-1.0-SNAPSHOT.jar`.
134+
This command creates a directory named `target`, that contains a file named `kafka-producer-consumer-1.0-SNAPSHOT.jar`. For ESP clusters the file will be `kafka-producer-consumer-esp-1.0-SNAPSHOT.jar`
125135
126136
3. Replace `sshuser` with the SSH user for your cluster, and replace `CLUSTERNAME` with the name of your cluster. Enter the following command to copy the `kafka-producer-consumer-1.0-SNAPSHOT.jar` file to your HDInsight cluster. When prompted enter the password for the SSH user.
127137
128138
```cmd
129-
scp ./target/kafka-producer-consumer-1.0-SNAPSHOT.jar [email protected]:kafka-producer-consumer.jar
139+
scp ./target/kafka-producer-consumer*.jar [email protected]:kafka-producer-consumer.jar
130140
```
131141
132142
## <a id="run"></a> Run the example
@@ -165,6 +175,7 @@ If you would like to skip this step, prebuilt jars can be downloaded from the `P
165175
166176
```bash
167177
java -jar kafka-producer-consumer.jar consumer myTest $KAFKABROKERS
178+
scp ./target/kafka-producer-consumer*.jar [email protected]:kafka-producer-consumer.jar
168179
```
169180
170181
The records read, along with a count of records, is displayed.
@@ -200,6 +211,12 @@ Consumption by clients within the same group is handled through the partitions f
200211
201212
Records stored in Kafka are stored in the order they're received within a partition. To achieve in-ordered delivery for records *within a partition*, create a consumer group where the number of consumer instances matches the number of partitions. To achieve in-ordered delivery for records *within the topic*, create a consumer group with only one consumer instance.
202213

214+
## Common Issues faced
215+
216+
1. **Topic creation fails** If your cluster is Enterprise Security Pack enabled, use the [pre-built JAR files for producer and consumer](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started/blob/master/Prebuilt-Jars/kafka-producer-consumer-esp.jar). The ESP jar can be built from from the code in the [`DomainJoined-Producer-Consumer` subdirectory](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started/tree/master/DomainJoined-Producer-Consumer). Note that the producer and consumer properties ave an additional property `CommonClientConfigs.SECURITY_PROTOCOL_CONFIG` for ESP enabled clusters.
217+
218+
2. **Facing issue with ESP enabled clusters** If produce and consume operations fail and you are using an ESP enabled cluster, check that the user `kafka` is present in all Ranger policies. If it is not present, add it to all Ranger policies.
219+
203220
## Clean up resources
204221

205222
To clean up the resources created by this tutorial, you can delete the resource group. Deleting the resource group also deletes the associated HDInsight cluster, and any other resources associated with the resource group.

0 commit comments

Comments
 (0)