Home > OS >  Get Data From Kafka Consumer As Text
Get Data From Kafka Consumer As Text

Time:07-08

I was trying to get the data from a kafka-consumer using this command

kubectl exec -it -n me2 kubectl get po -n me2 | grep central | awk '{print $1}' | head -1 -- /usr/bin/kafka-console-consumer --bootstrap-server me-ckaf-kafka-headless:9092 --topic CdrToUsageRepRating --from-beginning

you don't need to understand the command im just asking about the kafka part

when I use this command the consumed event doesn't returned as text I mean it is not like when you use "cat" command this is a problem for me because I'm trying to automate this and I used the SSHLibrary in Robot framework there are some functions in this library that can return the result of any completed command and the command above is not a completed command which return a result "it is like I'm entering the consumer " how can I get the Consumed events as a text

CodePudding user response:

Kafka consumers run endlessly.

You'll need to add --max-messages property to be able to have that command "return" data to some other remote execution framework

CodePudding user response:

Can you try passing formatter parameter along with SerDe in the command, something like this.

kafka-console-consumer --bootstrap-server localhost:9096 --topic CdrToUsageRepRating --from-beginning --formatter kafka.tools.DefaultMessageFormatter --property print.key=true --property print.value=true --property key.deserializer=org.apache.kafka.common.serialization.StringDeserializer --property value.deserializer=org.apache.kafka.common.serialization.LongDeserializer
  • Related