Skip to content

Commit 2f4f98d

Browse files
docs: refine new quick start for producing and consuming messages in cli (#566)
1 parent c3fa820 commit 2f4f98d

File tree

2 files changed

+138
-88
lines changed

2 files changed

+138
-88
lines changed

docs/rhoas/rhoas-produce-consume/README.adoc

Lines changed: 127 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -76,133 +76,182 @@ WARNING: This content is generated by running npm --prefix .build run generate:a
7676
END GENERATED ATTRIBUTES
7777
////
7878

79-
[id="chap-produce-consume-rhoas-cli"]
80-
= Getting started with producing and conuming messages in Rhoas Cli for {product-long-kafka}
79+
[id="chap-producing-consuming-rhoas-cli"]
80+
= Producing and consuming messages using the rhoas CLI
8181
ifdef::context[:parent-context: {context}]
82-
:context: getting-started-produce-consume
82+
:context: produce-consume-rhoas-cli
8383

8484
// Purpose statement for the assembly
8585
[role="_abstract"]
86-
As a developer of applications and services, you can use the Rhoas Cli to create and read message in {product-long-kafka} and third-party systems.
86+
As a developer of applications and services, you can use the `rhoas` command-line interface (CLI) to produce and consume messages for Kafka instances in {product-long-kafka}. This is a useful way to test and debug your Kafka instances.
8787

88-
In this example, you will produce messages to a kafka instance and consume them in the Rhoas Cli.
88+
.Prerequisites
89+
ifndef::community[]
90+
* You have a Red Hat account.
91+
endif::[]
92+
* You have a running Kafka instance in {product-kafka}.
93+
* You've installed the latest version of the `rhoas` CLI. See {base-url}{installation-guide-url-cli}[Installing and configuring the rhoas CLI^].
8994

9095
// Condition out QS-only content so that it doesn't appear in docs.
9196
// All QS anchor IDs must be in this alternate anchor ID format `[#anchor-id]` because the ascii splitter relies on the other format `[id="anchor-id"]` to generate module files.
9297
ifdef::qs[]
9398
[#description]
9499
====
95-
Learn how to produce and consume message in {product-long-rhoas}.
100+
Learn how to use the `rhoas` command-line interface (CLI) to produce and consume messages for a Kafka instance.
96101
====
97102

98103
[#introduction]
99104
====
100-
Welcome to the quick start for producing and consuming messages in the Rhoas Cli.
101-
102-
In this quick start, you will learn how to produce messages to a kafka instance and consume them in the Rhoas Cli.
103-
105+
Welcome to the quick start for producing and consuming Kafka messages using the `rhoas` command-line interface (CLI).
104106
107+
In this quick start, you'll use a CLI command to produce messages to different topic partitions in a Kafka instance. You'll then use the {product-long-kafka} web console to inspect the messages. When you're ready, you'll use another CLI command to consume the messages.
105108
====
106109
endif::[]
107110

108-
ifndef::qs[]
109-
== Overview
110-
111-
{product-long-kafka} is a cloud service that simplifies the process of running Apache Kafka. Apache Kafka is an open-source, distributed, publish-subscribe messaging system for creating fault-tolerant, real-time data feeds.
112-
113-
You can use {product-long-connectors} to configure communication between {product-kafka} instances and external services and applications. {product-long-connectors} allow you to configure how data moves from one endpoint to another without writing code.
114-
115-
The following diagram illustrates how data flows from a data source through a data source connector to a Kafka topic. And how data flows from a Kafka topic to a data sink through a data sink connector.
116-
117-
[.screencapture]
118-
.{product-long-connectors} data flow
119-
image::connectors-diagram.png[Illustration of data flow from data source through Kafka to data sink]
120-
121-
endif::[]
122-
123-
[id="proc-configure-kafka-instance_{context}"]
124-
== Configuring the {product-kafka} instance
111+
[id="proc-creating-kafka-topic-for-cli-production-consumption_{context}"]
112+
== Creating a Kafka topic in {product-kafka}
125113

126114
[role="_abstract"]
127-
After you create a {product-kafka} instance, configure by performing the following tasks:
115+
In this task, you'll create a new topic in your Kafka instance. You'll use this topic in later tasks to produce and consume messages.
128116

129-
* Create *Kafka topics* to store messages sent by you and make them available to consumers.
130-
131-
For this example, you create one Kafka topic, named *test-topic* which will be used for all commands in the following examples.
132-
133-
ifdef::qs[]
134117
.Prerequisites
135-
* You've created a {product-kafka} instance and the instance is in the *Ready* state.
136-
endif::[]
118+
* You've created a Kafka instance in {product-long-kafka} and the instance is in the *Ready* state.
137119

138120
.Procedure
139-
. Create a Kafka topic for your kafka instance:
140-
.. In the OpenShift Application Services web console, select *Streams for Apache Kafka* > *Kafka Instances*.
141-
.. Click the name of the {product-kafka} instance that you created.
142-
.. Select the *Topics* tab, and then click *Create topic*.
143-
.. Type a unique name for your topic. For example, type *test-topic* for *Topic Name*.
144-
.. Accept the default settings for message retention, and replicas. But set the partition count to *2*.
121+
. On the {service-url-kafka}[Kafka Instances^] page of the {product-kafka} web console, click the Kafka instance that you want to add a topic to.
122+
. Select the *Topics* tab.
123+
. Click *Create topic* and follow the guided steps to define the topic details.
124+
+
125+
You must specify the following topic properties:
126+
127+
* *Topic name*: For this quick start, enter `test-topic` as the topic name.
128+
* *Partitions*: Set the number of partitions for the topic. For this quick start, set the value to `2`.
129+
* *Message retention*: Set the message retention time and size. For this quick start, set the retention time to `A week` and the retention size to `Unlimited`.
130+
* *Replicas*: For this release of {product-kafka}, replica values are preconfigured. The number of partition replicas and the minimum number of follower replicas that must be in sync with a partition leader are both set to `1`.
131+
+
132+
After you complete the setup, the new topic appears on the *Topics* page.
145133

146-
ifdef::qs[]
147134
.Verification
148-
* Did you create a topic for the kafka instance?
135+
ifdef::qs[]
136+
* Does `test-topic` appear on the *Topics* page?
137+
endif::[]
138+
ifndef::qs[]
139+
* Verify that `test-topic` appears on the *Topics* page.
149140
endif::[]
150141

151-
152-
[id="proc-produce-message_{context}"]
153-
== Producing a message to a {product-kafka} instance
142+
[id="proc-producing-messages_{context}"]
143+
== Producing messages to your Kafka instance
154144

155145
[role="_abstract"]
156-
You can produce your own message from the Cli instead of using an application. This is very useful for testing and debuging your {product-kafka} instance.
146+
When you have a Kafka instance with a topic, you're ready to use the CLI to produce messages. In this task, you'll produce four messages to your Kafka instance.
157147

158148
.Prerequisites
159-
. You're logged in to the OpenShift Application Services web console at {service-url-connectors}[^].
160-
. You configured a {product-kafka} instance for connectors as described _Configuring the {product-kafka} instance for use with {product-long-connectors}_.
161-
. You are logged into the Rhoas Cli with your OpenShift Application Services account using `rhoas login`.
149+
* You've created `test-topic` on your Kafka instance.
162150

163151
.Procedure
164-
. To produce a message to your kafka topic use the following command `rhoas kafka topic produce --name=test-topic` and enter a value when prompted, for example enter `Hello world!`.
165-
166-
. Read the message
167-
.. In the OpenShift Application Services web console, select *Streams for Apache Kafka* > *Kafka Instances*.
168-
.. Click the name of the {product-kafka} instance that you created.
169-
.. Select the *Topics* tab, and then click the name of your topic.
170-
.. Select the *Messages* tab, and see the message you create from the Rhoas Cli
171-
172-
. By default any message you create is sent to the *0* partition. To create a message for the *1* partition run the following and enter another value `rhoas kafka topic produce --name=test-topic --partition=0`.
173-
174-
. Go back to the messages tab in the topic and see if your message is now on a different partition.
152+
. Log in to the `rhoas` CLI.
153+
+
154+
[source]
155+
----
156+
$ rhoas login
157+
----
158+
159+
. Specify the Kafka instance that you want to produce messages to.
160+
+
161+
[source,subs="+quotes"]
162+
----
163+
$ rhoas kafka use --name=_<my-kafka-instance>_
164+
----
165+
166+
. Produce your first message to `test-topic`.
167+
+
168+
[source]
169+
----
170+
rhoas kafka topic produce --name=test-topic
171+
----
172+
+
173+
You're prompted to enter a message value.
174+
175+
. Enter `First message` as the message value.
176+
177+
. Repeat the previous steps to produce your second and third messages to `test-topic`. Enter `Second message` and `Third message` as the message values.
178+
179+
. Produce your fourth and final message to `test-topic`. This time, specify a partition value of `1` and a custom message key. An example is shown below.
180+
+
181+
[source]
182+
----
183+
rhoas kafka topic produce --name=test-topic --partition=1 --key="{'location': 'us-east-1'}"
184+
----
185+
186+
. Enter `Fourth message` as the value of the final message.
187+
188+
. To view the messages in the {product-long-kafka} {service-url-kafka}[web console^], perform the following actions:
189+
.. On the *Kafka Instances* page, click the name of your Kafka instance.
190+
.. Select the *Topics* tab, and then click `test-topic`.
191+
.. Select the *Messages* tab.
192+
+
193+
The messages table shows the messages you produced.
194+
.. Observe the following details about the messages you produced:
195+
+
196+
* Because you didn't specify a partition value when producing the first three messages, these messages all went to partition `0` by default.
197+
* The three messages on partition `0` have offset values of `0`, `1`, and `2`.
198+
* The final message is on partition `1` and has the custom key value that you specified.
175199

176200
.Verification
177-
* Does running the commands produce messages?
178-
179-
.. In the OpenShift Application Services web console, select *Streams for Apache Kafka* > *Kafka Instances*.
180-
.. Click the Kafka instance that you created.
181-
.. Click the *Topics* tab and then click the topic that you specified for your {product-kafka} instance.
182-
.. Click the *Messages* tab to see a `Hello World!` message.
183-
201+
ifdef::qs[]
202+
* Does the messages table show the four messages that you produced?
203+
endif::[]
204+
ifndef::qs[]
205+
* Verify that the messages table shows the four messages you produced.
206+
endif::[]
184207

185-
[id="proc-consume-message_{context}"]
186-
== Consuming messages from a {product-kafka} instance
208+
[id="proc-consuming-messages_{context}"]
209+
== Consuming messages from your Kafka instance
187210
[role="_abstract"]
188-
You can consume your own message from the Cli instead of using an application. This is very useful for testing and debuging your {product-kafka} instance.
211+
When you've produced messages to your Kafka instance and verified them using the {product-long-kafka} web console, you're ready to consume the messages. In this task, you'll use the CLI to consume the messages.
189212

190213
.Prerequisites
191-
. You're logged in to the OpenShift Application Services web console at {service-url-connectors}[^].
192-
. You configured a {product-kafka} instance for connectors as described _Configuring the {product-kafka} instance for use with {product-long-connectors}_.
193-
. You are logged into the Rhoas Cli with your OpenShift Application Services account using `rhoas login`.
214+
* You've produced messages to `test-topic` in your Kafka instance.
215+
* You're logged in to the `rhoas` CLI.
194216

195217
.Procedure
196-
. To consume a message to your kafka topic use the following command `rhoas kafka topic consume --name=test-topic`. You will now see all messages you produced to the topic.
197-
. Just like produce set the `--partition` flag to consume from a specific partition. Run `rhoas kafka topic consume --name=test-topic --partition=1`. You will now see all messages you produced to the topic on the *1* partition.
218+
. Specify the Kafka instance that you want to consume messages from.
219+
+
220+
[source,subs="+quotes"]
221+
----
222+
$ rhoas kafka use --name=_<my-kafka-instance>_
223+
----
224+
225+
. Consume the messages on partition `0` of `test-topic`.
226+
+
227+
[source]
228+
----
229+
rhoas kafka topic consume --name=test-topic --partition=0
230+
----
231+
+
232+
The CLI displays the messages. Observe that because you didn't specify an offset value, the CLI displays *all* of the messages on partition `0`.
233+
234+
. Consume the third message that you produced by specifying the appropriate partition and offset values.
235+
+
236+
[source]
237+
----
238+
rhoas kafka topic consume --name=test-topic --partition=0 --offset=2
239+
----
240+
241+
. Consume the fourth message, which you produced to partition `1` of the topic.
242+
+
243+
[source]
244+
----
245+
rhoas kafka topic consume --name=test-topic --partition=1
246+
----
198247

199248
.Verification
200-
* Does running the commands output messages on the correct partitions?
249+
* When you entered the `kafka topic consume` command, did you see the expected messages?
201250

202251
ifdef::qs[]
203252
[#conclusion]
204253
====
205-
Congratulations! You successfully completed producing and conuming messages in Rhoas Cli for {product-long-kafka} quick start.
254+
Congratulations! You successfully completed the quick start for producing and consuming messages using the `rhoas` CLI.
206255
====
207256
endif::[]
208257

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
apiVersion: console.openshift.io/v1
22
kind: QuickStarts
33
metadata:
4-
name: Produce and consume in Rhoas Cli
4+
name: producing-consuming-cli
55
annotations:
6-
draft: true
7-
order: 6
6+
draft: false
7+
order: 3
88
spec:
99
version: 0.1
1010
type:
1111
text: Quick Start
1212
color: green
13-
displayName: !snippet/title README.adoc#chap-produce-consume-rhoas-cli
14-
durationMinutes: 20
13+
displayName: !snippet/title README.adoc#chap-producing-consuming-rhoas-cli
14+
durationMinutes: 10
1515
icon: data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzOCIgaGVpZ2h0PSIzOCIgdmlld0JveD0iMCAwIDM4IDM4Ij48ZGVmcz48c3R5bGU+LmF7ZmlsbDojZmZmO30uYntmaWxsOiNlMDA7fTwvc3R5bGU+PC9kZWZzPjxwYXRoIGQ9Ik0yOCwxSDEwYTksOSwwLDAsMC05LDlWMjhhOSw5LDAsMCwwLDksOUgyOGE5LDksMCwwLDAsOS05VjEwYTksOSwwLDAsMC05LTlaIi8+PHBhdGggY2xhc3M9ImEiIGQ9Ik0yMiwyNS42MjVIMTNhLjYyNS42MjUsMCwwLDEsMC0xLjI1aDlhMi4zNzUsMi4zNzUsMCwwLDAsMC00Ljc1SDE1YTMuNjI1LDMuNjI1LDAsMCwxLDAtNy4yNUgyNWEuNjI1LjYyNSwwLDAsMSwwLDEuMjVIMTVhMi4zNzUsMi4zNzUsMCwwLDAsMCw0Ljc1aDdhMy42MjUsMy42MjUsMCwwLDEsMCw3LjI1WiIvPjxwYXRoIGNsYXNzPSJiIiBkPSJNMjUsMTYuNjI1QTMuNjI1LDMuNjI1LDAsMSwxLDI4LjYyNSwxMywzLjYyODg2LDMuNjI4ODYsMCwwLDEsMjUsMTYuNjI1Wm0wLTZBMi4zNzUsMi4zNzUsMCwxLDAsMjcuMzc1LDEzLDIuMzc3NywyLjM3NzcsMCwwLDAsMjUsMTAuNjI1WiIvPjxwYXRoIGNsYXNzPSJiIiBkPSJNMTMsMjguNjI1QTMuNjI1LDMuNjI1LDAsMSwxLDE2LjYyNSwyNSwzLjYyODg2LDMuNjI4ODYsMCwwLDEsMTMsMjguNjI1Wm0wLTZBMi4zNzUsMi4zNzUsMCwxLDAsMTUuMzc1LDI1LDIuMzc3NywyLjM3NzcsMCwwLDAsMTMsMjIuNjI1WiIvPjwvc3ZnPg==
1616
description: !snippet README.adoc#description
1717
prerequisites:
18-
- A Red Hat identity
19-
- You've created a Kafka instance and the instance is in `Ready` state. See the _Getting started with OpenShift Streams for Apache Kafka_ quick start.
18+
- You have a Red Hat identity
19+
- You've created a Kafka instance and the instance is in the `Ready` state. See the _Getting started with OpenShift Streams for Apache Kafka_ quick start.
20+
- You've installed the latest version of the rhoas CLI. See <a href="https://access.redhat.com/documentation/en-us/red_hat_openshift_application_services/1/guide/bb30ee92-9e0a-4fd6-a67f-aed8910d7da3">Installing and configuring the rhoas CLI</a>.
2021
introduction: !snippet README.adoc#introduction
2122
tasks:
22-
- !snippet/proc README.adoc#proc-configure-kafka-instance
23-
- !snippet/proc README.adoc#proc-produce-message
24-
- !snippet/proc README.adoc#proc-consume-message
23+
- !snippet/proc README.adoc#proc-creating-kafka-topic-for-cli-production-consumption
24+
- !snippet/proc README.adoc#proc-producing-messages
25+
- !snippet/proc README.adoc#proc-consuming-messages
2526
conclusion: !snippet README.adoc#conclusion

0 commit comments

Comments
 (0)