Skip to content

Commit e77948a

Browse files
authored
Merge pull request #90349 from dagiro/devops3b
devops3b
2 parents 1d70834 + 20f8914 commit e77948a

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

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

Lines changed: 22 additions & 21 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: 06/24/2019
10+
ms.date: 10/08/2019
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

@@ -55,9 +55,9 @@ The important things to understand in the `pom.xml` file are:
5555
```xml
5656
<!-- Kafka client for producer/consumer operations -->
5757
<dependency>
58-
<groupId>org.apache.kafka</groupId>
59-
<artifactId>kafka-clients</artifactId>
60-
<version>${kafka.version}</version>
58+
<groupId>org.apache.kafka</groupId>
59+
<artifactId>kafka-clients</artifactId>
60+
<version>${kafka.version}</version>
6161
</dependency>
6262
```
6363

@@ -108,7 +108,7 @@ In this code, the consumer is configured to read from the start of the topic (`a
108108

109109
### Run.java
110110

111-
The [Run.java](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started/blob/master/Producer-Consumer/src/main/java/com/microsoft/example/Run.java) file provides a command-line interface that runs either the producer or consumer code. You must provide the Kafka broker host information as a parameter. You can optionally include a group ID value, which is used by the consumer process. If you create multiple consumer instances using the same group ID, they will load balance reading from the topic.
111+
The [Run.java](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started/blob/master/Producer-Consumer/src/main/java/com/microsoft/example/Run.java) file provides a command-line interface that runs either the producer or consumer code. You must provide the Kafka broker host information as a parameter. You can optionally include a group ID value, which is used by the consumer process. If you create multiple consumer instances using the same group ID, they'll load balance reading from the topic.
112112

113113
## Build and deploy the example
114114

@@ -136,55 +136,56 @@ The [Run.java](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started
136136
137137
```
138138
139-
2. Install [jq](https://stedolan.github.io/jq/), a command-line JSON processor. From the open SSH connection, enter following command to install `jq`:
139+
1. Install [jq](https://stedolan.github.io/jq/), a command-line JSON processor. From the open SSH connection, enter following command to install `jq`:
140140
141141
```bash
142142
sudo apt -y install jq
143143
```
144144
145-
3. Set up environment variables. Replace `PASSWORD` and `CLUSTERNAME` with the cluster login password and cluster name respectively, then enter the command:
145+
1. Set up password variable. Replace `PASSWORD` with the cluster login password, then enter the command:
146146
147147
```bash
148148
export password='PASSWORD'
149-
export clusterNameA='CLUSTERNAME'
150149
```
151150
152-
4. Extract correctly cased cluster name. The actual casing of the cluster name may be different than you expect, depending on how the cluster was created. This command will obtain the actual casing, store it in a variable, and then display the correctly cased name, and the name you provided earlier. Enter the following command:
151+
1. Extract correctly cased cluster name. The actual casing of the cluster name may be different than you expect, depending on how the cluster was created. This command will obtain the actual casing, and then store it in a variable. Enter the following command:
153152
154153
```bash
155-
export clusterName=$(curl -u admin:$password -sS -G "https://$clusterNameA.azurehdinsight.net/api/v1/clusters" \
156-
| jq -r '.items[].Clusters.cluster_name')
157-
echo $clusterName, $clusterNameA
154+
export clusterName=$(curl -u admin:$password -sS -G "http://headnodehost:8080/api/v1/clusters" | jq -r '.items[].Clusters.cluster_name')
158155
```
156+
> [!Note]
157+
> If you're doing this process from outside the cluster, there is a different procedure for storing the cluster name. Get the cluster name in lower case from the Azure portal. Then, substitute the cluster name for `<clustername>` in the following command and execute it: `export clusterName='<clustername>'`.
159158
160-
5. To get the Kafka broker hosts and the Apache Zookeeper hosts, use the following command:
159+
1. To get the Kafka broker hosts, use the following command:
161160
162161
```bash
163-
export KAFKABROKERS=`curl -sS -u admin:$password -G https://$clusterName.azurehdinsight.net/api/v1/clusters/$clusterName/services/KAFKA/components/KAFKA_BROKER \
164-
| jq -r '["\(.host_components[].HostRoles.host_name):9092"] | join(",")' | cut -d',' -f1,2`
162+
export KAFKABROKERS=$(curl -sS -u admin:$password -G https://$clusterName.azurehdinsight.net/api/v1/clusters/$clusterName/services/KAFKA/components/KAFKA_BROKER | jq -r '["\(.host_components[].HostRoles.host_name):9092"] | join(",")' | cut -d',' -f1,2);
165163
```
166164
167-
6. Create Kafka topic, `myTest`, by entering the following command:
165+
> [!Note]
166+
> This command requires Ambari access. If your cluster is behind an NSG, run this command from a machine that can access Ambari.
167+
168+
1. Create Kafka topic, `myTest`, by entering the following command:
168169
169170
```bash
170171
java -jar kafka-producer-consumer.jar create myTest $KAFKABROKERS
171172
```
172173
173-
7. To run the producer and write data to the topic, use the following command:
174+
1. To run the producer and write data to the topic, use the following command:
174175
175176
```bash
176177
java -jar kafka-producer-consumer.jar producer myTest $KAFKABROKERS
177178
```
178179
179-
8. Once the producer has finished, use the following command to read from the topic:
180+
1. Once the producer has finished, use the following command to read from the topic:
180181
181182
```bash
182183
java -jar kafka-producer-consumer.jar consumer myTest $KAFKABROKERS
183184
```
184185
185186
The records read, along with a count of records, is displayed.
186187
187-
9. Use __Ctrl + C__ to exit the consumer.
188+
1. Use __Ctrl + C__ to exit the consumer.
188189
189190
### Multiple consumers
190191
@@ -213,7 +214,7 @@ Consumption by clients within the same group is handled through the partitions f
213214
> [!IMPORTANT]
214215
> There cannot be more consumer instances in a consumer group than partitions. In this example, one consumer group can contain up to eight consumers since that is the number of partitions in the topic. Or you can have multiple consumer groups, each with no more than eight consumers.
215216
216-
Records stored in Kafka are stored in the order they are 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.
217+
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.
217218

218219
## Clean up resources
219220

@@ -230,4 +231,4 @@ To remove the resource group using the Azure portal:
230231
In this document, you learned how to use the Apache Kafka Producer and Consumer API with Kafka on HDInsight. Use the following to learn more about working with Kafka:
231232

232233
> [!div class="nextstepaction"]
233-
> [Analyze Apache Kafka logs](apache-kafka-log-analytics-operations-management.md)
234+
> [Analyze Apache Kafka logs](apache-kafka-log-analytics-operations-management.md)

0 commit comments

Comments
 (0)