-
Notifications
You must be signed in to change notification settings - Fork 9
Producing
Jimmy Bonds edited this page Dec 21, 2018
·
3 revisions
- Verify the Topic details:
# > kafkactl topics testtopic --meta
TOPIC PART OFFSET LEADER REPLICAS ISRs OFFLINE
testtopic 0 0 5 [5] [5] []
testtopic 1 0 4 [4] [4] []
testtopic 2 0 1 [1] [1] []
testtopic 3 0 3 [3] [3] []
testtopic 4 0 2 [2] [2] []
- Using Stdin:
Send to Partitions 1 and 4:
# > echo 'Friday, December 21, 2018 10:33:07 AM' | kafkactl send -t testtopic -p "1,4"
Confirm Offset Change, then Consume/Read:
# > kafkactl topics testtopic --meta
TOPIC PART OFFSET LEADER REPLICAS ISRs OFFLINE
testtopic 0 0 5 [5] [5] []
testtopic 1 1 4 [4] [4] []
testtopic 2 0 1 [1] [1] []
testtopic 3 0 3 [3] [3] []
testtopic 4 1 2 [2] [2] []
# > kafkactl read --topic testtopic -p 1 -o 0
TOPIC:[testtopic] PARTITION:[1] OFFSET:[0]
Friday, December 21, 2018 10:33:07 AM
# > kafkactl read -t testtopic -p 4 -o 0
TOPIC:[testtopic] PARTITION:[4] OFFSET:[0]
Friday, December 21, 2018 10:33:07 AM
- Using cmdline Arguments
Send Key and Value to All Partitions:
# > kafkactl send --topic testtopic --key myKey --message myMessageHere --allparts
# > kafkactl read -t testtopic --partition 3 --offset 1 --key
TOPIC:[testtopic] PARTITION:[3] OFFSET:[1] KEY:[myKey]
myMessageHere
Show the last Offset of each Partition of a Topic using tail:
# > kafkactl tail --topic testtopic
myMessageHere
myMessageHere
myMessageHere
myMessageHere
myMessageHere
^Csignal: interrupt
- Using a Console Producer
Launch a Console Producer by specifying no --message Arguments or Stdin:
> kafkactl send --topic testtopic
Started Console Producer ... Partitions: Hashing
[kafkactl] # Typing my message here.
[kafkactl] # Again
[kafkactl] # Test
[kafkactl] # Ctrl+C to Quit
[kafkactl] # ^Csignal: interrupt
Stopping Console Producer ...
Stopped Console Producer
Use the Console Producer with Specific Partitions:
> kafkactl send --topic testtopic --partitions "2,3"
Started Console Producer ... Partitions: [2 3]
[kafkactl] # Messages only sent to Partitions 2 and 3
[kafkactl] # Hello
[kafkactl] # Test
[kafkactl] # ^Csignal: interrupt
Stopping Console Producer ...
Stopped Console Producer
Produces messages to a Kafka topic.
Either by:
Command arguments,
Stdin,
Console Producer (launched with no arguments or stdin.)
Usage:
kafkactl produce [flags]
Aliases:
produce, pro, send
Flags:
-a, --allparts Send to all Topic Partitions
-h, --help help for produce
-k, --key string Optional key to produce/send
-m, --message string Message/Value to produce/send, Wins over Stdin.
-p, --partitions string Send to each Comma Separated (eg: "0,1,7,9") Partition)
Global Flags:
-b, --broker string Bootstrap Kafka Broker
-F, --fast Use go routine methods when available for faster results (default true)
-g, --group string Specify a Target Group
--port string Port used for Bootstrap Kafka Broker (default "9092")
-t, --topic string Specify a Target Topic
-v, --verbose Display any additional info and error output.