This message was deleted.
# general
s
This message was deleted.
d
It means that the message contents are encoded as JSON strings and serialized/deserialized into POJOs based on the schema definition inside the clients. See this section of the docs for more details.
a
Okay great, that clears that up and the bug I posted still stands.
d
Which bug?
a
I’ve found that the pulsar-client python dependency has some issues also with
AVROSchema()
. 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:
Copy code
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:
Copy code
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:
Copy code
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.
c
Despite the name, Pulsar doesn't use JSON-Schema to describe JSON encoded payloads but it uses Avro Schema instead (Avro Schema can describe both Avro and JSON structures).
d
I'm glad I'm not the only one who was confused by this.
😀 1
d
It took me a minute as well….. 😃
a
Yeah the documentation is confusing, and I’ve been trying to get Java and Python client producers/subscribers working (trying to put together my own documentation that can be made public) but I think there are still some gaps in the supporting clients.
The Java Pulsar client seems to have issues deserializing JSON Avro schemas (traced it down to the line of code but I’m not sure of the business logic), no problems with Byte Avro Schemas.
d
Re: documentation…..
a
Yeah I’m putting some “from zero” markup docs together.
👍 1
Just keep facing bugs from time to time 🙂