From 471a97e9f5ad162c3d3e52668e045a689863f6a4 Mon Sep 17 00:00:00 2001 From: Wojciech Trocki Date: Tue, 12 Jul 2022 14:42:43 +0200 Subject: [PATCH] fix: public consume and produce commands (#1637) --- docs/commands/rhoas_kafka_topic.md | 2 + docs/commands/rhoas_kafka_topic_consume.md | 70 ++++++++++++++++++++++ docs/commands/rhoas_kafka_topic_produce.md | 58 ++++++++++++++++++ pkg/cmd/kafka/topic/consume/consume.go | 1 - pkg/cmd/kafka/topic/produce/produce.go | 1 - 5 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 docs/commands/rhoas_kafka_topic_consume.md create mode 100644 docs/commands/rhoas_kafka_topic_produce.md diff --git a/docs/commands/rhoas_kafka_topic.md b/docs/commands/rhoas_kafka_topic.md index dca4ab10e..2ceef3619 100644 --- a/docs/commands/rhoas_kafka_topic.md +++ b/docs/commands/rhoas_kafka_topic.md @@ -30,9 +30,11 @@ rhoas kafka topic list ### SEE ALSO * [rhoas kafka](rhoas_kafka.md) - Create, view, use, and manage your Kafka instances +* [rhoas kafka topic consume](rhoas_kafka_topic_consume.md) - Consume messages from a topic * [rhoas kafka topic create](rhoas_kafka_topic_create.md) - Create a topic * [rhoas kafka topic delete](rhoas_kafka_topic_delete.md) - Delete a topic * [rhoas kafka topic describe](rhoas_kafka_topic_describe.md) - Describe a topic * [rhoas kafka topic list](rhoas_kafka_topic_list.md) - List all topics +* [rhoas kafka topic produce](rhoas_kafka_topic_produce.md) - Produce a new message to a topic * [rhoas kafka topic update](rhoas_kafka_topic_update.md) - Update configuration details for a Kafka topic diff --git a/docs/commands/rhoas_kafka_topic_consume.md b/docs/commands/rhoas_kafka_topic_consume.md new file mode 100644 index 000000000..bf23d4887 --- /dev/null +++ b/docs/commands/rhoas_kafka_topic_consume.md @@ -0,0 +1,70 @@ +## rhoas kafka topic consume + +Consume messages from a topic + +### Synopsis + +Consume messages from a given topic. By default, all messages on the topic are consumed and printed in the format that you specify. You can spcecify filters +such as a starting offset or a starting time for message production. + +If you add the --wait flag, the CLI waits for messages to be produced starting from when you run the command and ignores any limit or offset specified. + + +``` +rhoas kafka topic consume [flags] +``` + +### Examples + +``` +# Consume from a topic +$ rhoas kafka topic consume --name=topic-1 + +# Consume from a topic and output to YAML format +$ rhoas kafka topic consume --name=topic-1 --format=yaml + +# Consume from a topic by continually polling the topic for new messages +$ rhoas kafka topic consume --name=topic-1 --wait + +# Consume from a topic starting from a time specified in default ISO time format +$ rhoas kafka topic consume --name=topic-1 --from-date=2022-06-17T07:05:34.0000Z + +# Consume from a topic starting from a time specified in Unix epoch time format +$ rhoas kafka topic consume --name=topic-1 --wait --from-timestamp=1656346796 + +# Consume from a topic starting from an offset value +$ rhoas kafka topic consume --name=topic-1 --offset=15 + +# Consume from a topic starting from an offset value and with a specified message limit +$ rhoas kafka topic consume --name=topic-1 --offset=15 --limit=30 + +# Consume from topic and output to JSON format and using jq to read values +$ rhoas kafka topic consume --name=topic-1 --format=json | jq -rc .value + +``` + +### Options + +``` + --format string Format for printing produced messages (possible values are "json" and "yaml") (default "key-value") + --from-date string Consume only messages with a date later than the specified value (requied format is YYYY-MM-DDThh:mm:ss.ssssZ) + --from-timestamp string Consume only messages with a timestamp later than the specified value (required format is Unix epoch timestamp value) + --instance-id string Kafka instance ID. Uses the current instance if not set + --limit int32 Maximum number of messages to consume from topic (default 20) + --name string Topic name + --offset string Consume messages from an offset equal to or greater than the specified value + --partition int32 Consume messages from specified partition (value must be a positive integer) + --wait Wait for messages to consume from topic +``` + +### Options inherited from parent commands + +``` + -h, --help Show help for a command + -v, --verbose Enable verbose mode +``` + +### SEE ALSO + +* [rhoas kafka topic](rhoas_kafka_topic.md) - Create, describe, update, list, and delete topics + diff --git a/docs/commands/rhoas_kafka_topic_produce.md b/docs/commands/rhoas_kafka_topic_produce.md new file mode 100644 index 000000000..4860e24ac --- /dev/null +++ b/docs/commands/rhoas_kafka_topic_produce.md @@ -0,0 +1,58 @@ +## rhoas kafka topic produce + +Produce a new message to a topic + +### Synopsis + +Produce a message to a topic in a Kafka instance. Specify a file path for the CLI to read as the message value or use stdin to provide your message. You can specify the partition, key, and value. + + +``` +rhoas kafka topic produce [flags] +``` + +### Examples + +``` +# Produce a single message to a topic from a file and provide a custom message key +$ rhoas kafka topic produce --name=users --file="./message.json" --key="{'location': 'us-east-1'}" + +# Produce to a topic from standard input +$ rhoas kafka topic produce --name=users + +# Produce to a topic from other command output +$ cat yourfile.json | rhoas kafka topic produce --name=users + +# Produce to a topic and fetch its offset value +$ rhoas kafka topic produce --name=topic-1 --file="./message.json" | jq .offset + +# Produce to a topic from a JSON file and filter using jq +$ cat input.json | jq .data.value | rhoas kafka topic produce --name=topic-1 + +# Produce to a topic and specified partition +$ rhoas kafka topic produce --name=topic-1 --file="./message.json" --partition=1 + +``` + +### Options + +``` + --file string Path to file containing message value + --format string Format for printing produced messages (possible values are "json" and "yaml") (default "json") + --instance-id string Kafka instance ID. Uses the current instance if not set + --key string Message key. Empty if not set + --name string Topic name + --partition int32 Partition number for the message. Must be a positive integer value that is valid for the specified topic +``` + +### Options inherited from parent commands + +``` + -h, --help Show help for a command + -v, --verbose Enable verbose mode +``` + +### SEE ALSO + +* [rhoas kafka topic](rhoas_kafka_topic.md) - Create, describe, update, list, and delete topics + diff --git a/pkg/cmd/kafka/topic/consume/consume.go b/pkg/cmd/kafka/topic/consume/consume.go index e19285cc4..60d3e109d 100644 --- a/pkg/cmd/kafka/topic/consume/consume.go +++ b/pkg/cmd/kafka/topic/consume/consume.go @@ -65,7 +65,6 @@ func NewConsumeTopicCommand(f *factory.Factory) *cobra.Command { Short: f.Localizer.MustLocalize("kafka.topic.consume.cmd.shortDescription"), Long: f.Localizer.MustLocalize("kafka.topic.consume.cmd.longDescription"), Example: f.Localizer.MustLocalize("kafka.topic.consume.cmd.example"), - Hidden: true, Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) (err error) { if opts.kafkaID == "" { diff --git a/pkg/cmd/kafka/topic/produce/produce.go b/pkg/cmd/kafka/topic/produce/produce.go index 60017169d..768061e90 100644 --- a/pkg/cmd/kafka/topic/produce/produce.go +++ b/pkg/cmd/kafka/topic/produce/produce.go @@ -56,7 +56,6 @@ func NewProduceTopicCommand(f *factory.Factory) *cobra.Command { Short: f.Localizer.MustLocalize("kafka.topic.produce.cmd.shortDescription"), Long: f.Localizer.MustLocalize("kafka.topic.produce.cmd.longDescription"), Example: f.Localizer.MustLocalize("kafka.topic.produce.cmd.example"), - Hidden: true, Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) (err error) { if opts.kafkaID == "" {