提交 a26f67a2 编写于 作者: G Guangning 提交者: Sijie Guo

[Issue 5454][pulsar-client-cpp]Fix cpp client schema version (#5930)

Fixes #5454 


### Motivation

The current CPP client cannot correctly obtain the schema version, resulting in an error in parsing with java client when sending data with schema using python client.

Test code:

```
import pulsar
import json

from pulsar.schema import *

class Test(Record):
    name = String()
    id = Integer()

client = pulsar.Client('pulsar://localhost:6650');
producer = client.create_producer('test-producer-schema', schema=AvroSchema(Test))
producer.send(Test(name='Hello', id=1))
client.close()
```



### Modifications

* Add set schema version in msgmetadata

### Verifying this change

Add check schema version in unit test SchemaTest
上级 d6f90ddc
......@@ -287,6 +287,9 @@ void ProducerImpl::setMessageMetadata(const Message& msg, const uint64_t& sequen
msgMetadata.set_compression(CompressionCodecProvider::convertType(conf_.getCompressionType()));
msgMetadata.set_uncompressed_size(uncompressedSize);
}
if (!this->getSchemaVersion().empty()) {
msgMetadata.set_schema_version(this->getSchemaVersion());
}
}
void ProducerImpl::statsCallBackHandler(Result res, const MessageId& msgId, SendCallback callback,
......
......@@ -36,6 +36,9 @@ TEST(SchemaTest, testSchema) {
ProducerConfiguration producerConf;
producerConf.setSchema(SchemaInfo(AVRO, "Avro", exampleSchema));
res = client.createProducer("topic-avro", producerConf, producer);
// Check schema version
ASSERT_FALSE(producer.getSchemaVersion().empty());
producer.close();
ASSERT_EQ(ResultOk, res);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册