Slackbot
04/07/2023, 4:52 PMDavid K
04/07/2023, 5:09 PMAnthony Ikeda
04/07/2023, 5:11 PMDavid K
04/07/2023, 5:11 PMAnthony Ikeda
04/07/2023, 5:15 PMAVROSchema(). There is a work around but the documented approach https://pulsar.apache.org/docs/2.11.x/schema-get-started/#avro is not working - calling msg.value() when declaring:
class Example(Record):
a = Integer()
b = Integer()
consumer = client.subscribe(
'avro-schema-topic',
'sub',
schema=AvroSchema(Example))
msg = consumer.receive()
e = msg.value()
# In my attempt I'm using:
class Product(Record):
_avro_namespace = 'com.pulsar.workshop'
product_id = Integer()
product_name = String()
product_description = String()
consumer = client.subscribe(topic='<persistent://my-tenant/my-namespace/basic-topic-5>',
subscription_name='python-listener',
schema=AvroSchema(Product))
gives an error:
Traceback (most recent call last):
File "/Users/anthonyikeda/work/git/python-pulsar/message.py", line 26, in <module>
ex = msg.value()
^^^^^^^^^^^
File "/Users/anthonyikeda/work/git/python-pulsar/venv/lib/python3.11/site-packages/pulsar/__init__.py", line 130, in value
return self._schema.decode(self._message.data())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/anthonyikeda/work/git/python-pulsar/venv/lib/python3.11/site-packages/pulsar/schema/schema_avro.py", line 80, in decode
d = fastavro.schemaless_reader(buffer, self._schema)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "fastavro/_read.pyx", line 1107, in fastavro._read.schemaless_reader
File "fastavro/_read.pyx", line 1120, in fastavro._read.schemaless_reader
File "fastavro/_read.pyx", line 749, in fastavro._read._read_data
File "fastavro/_read.pyx", line 620, in fastavro._read.read_record
File "fastavro/_read.pyx", line 740, in fastavro._read._read_data
File "fastavro/_read.pyx", line 521, in fastavro._read.read_union
IndexError: list index out of range
But when you load the schema from a *.avsc file:
schema_definition = load_schema("product.avsc")
client = pulsar.Client('<pulsar://localhost:6650>')
consumer = client.subscribe(topic='<persistent://my-tenant/my-namespace/basic-topic-5>',
subscription_name='python-listener',
schema=AvroSchema(None, schema_definition=schema_definition))
There doesn’t seem to be a problem.Anthony Ikeda
04/07/2023, 5:16 PMChristophe Bornet
04/11/2023, 8:14 AMDevin G. Bost
04/14/2023, 6:12 PMDavid K
04/14/2023, 6:17 PMAnthony Ikeda
04/14/2023, 6:19 PMAnthony Ikeda
04/14/2023, 6:20 PMDavid K
04/14/2023, 6:21 PMAnthony Ikeda
04/14/2023, 6:21 PMAnthony Ikeda
04/14/2023, 6:21 PM