Hi, I have a very simple schema:
{"type":"record",
"name":"my record",
"fields":[{"name":"f1","type":"string"},
{"name":"BEHAVIOR_TIME","type":"string"}
]}
when I send this later message through `kafka-avro-console-producer`, the `kafka-avro-console-consumer` and the rest consumer api both decoded it well.
{"f1":"v2","BEHAVIOR_TIME":"2015-05-30 00:00:27.183"}
then I tried to use the **plane** console consumer
$ bin/kafka-console-consumer --topic test --zookeeper localhost:2181 --from-beginning
It returns binary code like this:
�v2.2015-05-30 00:00:27.183
Here's my question, can I decode this message by python's kafka-python module? I tried, but failed, Here is my code:
from kafka import KafkaClient, SimpleConsumer
import cStringIO
kafka_hosts = ['localhost:9092',]
topic = 'test'
consumer = SimpleConsumer(client, group="
test.avro.name", topic=topic, )
messages = consumer.get_messages(count=1, timeout=0.5)
msg = messages[0].message.value
print msg
schema = avro.schema.parse(avsc_str)
datum_reader = avro.io.DatumReader(schema)
reader = cStringIO.StringIO(msg)
decoder = avro.io.BinaryDecoder(reader)
print datum_reader.read(decoder)
output:
'\x00\x00\x00\x00\xa1\x04v3.2015-05-31 00:20:27.183'
{u'BEHAVIOR_TIME': u'', u'f1': u''}
the field contains no real value.