BewareMyPower commented on issue #9922: URL: https://github.com/apache/pulsar/issues/9922#issuecomment-801669922
Currently `AVRO`, `JSON` and `PROTOBUF` (not `PROTOBUF_NATIVE`) share the same schema validator. See https://github.com/apache/pulsar/blob/7d3317e290ca34918e10379b6592e28678cde90f/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/validator/SchemaDataValidator.java#L37-L43 Therefore, following code works well. ```c++ #include <iostream> #include <pulsar/Client.h> using namespace pulsar; int main() { Client client("pulsar://localhost:6650"); std::string exampleSchema = R"({"type":"record","name":"Example","namespace":"test","fields":[{"name":"a","type":"int"},{"name":"b","type":"double"}]})"; ProducerConfiguration producerConfig; SchemaInfo schema(SchemaType::PROTOBUF, "Protobuf", exampleSchema); producerConfig.setSchema(schema); Producer producer; Result result = client.createProducer("my-topic", producerConfig, producer); if (result != ResultOk) { std::cout << "Failed to create producer: " << result << std::endl; return -1; } client.close(); return 0; } ``` The logs is ``` 2021-03-18 14:30:45.723 INFO [0x1141d0e00] ConnectionPool:85 | Created connection for pulsar://localhost:6650 2021-03-18 14:30:45.724 INFO [0x700009a0a000] ClientConnection:372 | [[::1]:50989 -> [::1]:6650] Connected to broker 2021-03-18 14:30:45.749 INFO [0x700009a0a000] HandlerBase:54 | [persistent://public/default/my-topic, ] Getting connection from pool 2021-03-18 14:30:46.260 INFO [0x700009a0a000] ProducerImpl:176 | [persistent://public/default/my-topic, ] Created producer on broker [[::1]:50989 -> [::1]:6650] 2021-03-18 14:30:46.260 INFO [0x1141d0e00] ClientImpl:483 | Closing Pulsar client 2021-03-18 14:30:46.260 INFO [0x1141d0e00] ProducerImpl:581 | [persistent://public/default/my-topic, standalone-0-0] Closing producer for topic persistent://public/default/my-topic 2021-03-18 14:30:46.264 INFO [0x700009a0a000] ProducerImpl:624 | [persistent://public/default/my-topic, standalone-0-0] Closed producer 2021-03-18 14:30:46.264 INFO [0x700009a0a000] ClientConnection:1446 | [[::1]:50989 -> [::1]:6650] Connection closed 2021-03-18 14:30:46.264 INFO [0x1141d0e00] ProducerImpl:560 | Producer - [persistent://public/default/my-topic, standalone-0-0] , [batchMessageContainer = { BatchMessageContainer [size = 0] [bytes = 0] [maxSize = 1000] [maxBytes = 131072] [topicName = persistent://public/default/my-topic] [numberOfBatchesSent_ = 0] [averageBatchSize_ = 0] }] 2021-03-18 14:30:46.265 INFO [0x1141d0e00] ClientConnection:261 | [[::1]:50989 -> [::1]:6650] Destroyed connection ``` So the problem is with your JSON string from `google::protobuf::util::MessageToJsonString`. Could you print the `msgJson`? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
