Skip to content

the produce send msg wrong, can't be decoded by consumer #1

@miaojianxin

Description

@miaojianxin
writer = avro.io.DatumWriter(schema)
bytes_writer = io.BytesIO()
encoder = avro.io.BinaryEncoder(bytes_writer)
writer.write({"name": "123", "favorite_color": "111", "favorite_number": random.randint(0,10)}, encoder)
raw_bytes = bytes_writer.getvalue()
producer.send_messages(topic, raw_bytes)

in this way, the raw_bytes got in program not right, lack schema info. the avro python give example ,that's ok, but it through file, it is not what i want .

schema = avro.schema.parse('{"namespace": "example.avro","type": "record","name": "User","fields": [{"name": "name", "type": "string"},{"name": "favorite_number", "type": ["int", "null"]},{"name": "favorite_color", "type": ["string", "null"]}]}')

writer = DataFileWriter(open("/tmp/users.avro", "w"), DatumWriter(), schema)

s=json.loads('{"name":"china","favorite_number":256}')
writer.append(s)

writer.append({"name":"mjx","favorite_number":256})
writer.close()

producer = KafkaProducer(bootstrap_servers='192.168.10.247:9092')
with open('/tmp/users.avro', 'rb') as f:
for line in f.readlines():
producer.send('my-topic2', line)
break;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions