RobertIndie commented on issue #1296:
URL: 
https://github.com/apache/pulsar-client-go/issues/1296#issuecomment-2426283241

   Pulsar does not validate the structure of JSON messages against the topic's 
schema. It only checks if the producer's schema definition matches the broker's 
topic schema. In contrast, the Avro schema validates the message structure 
during both encoding and decoding. This is the same for the Java client. 
   
   If you need to verify message structure compatibility when sending the 
messages, you could use the Avro Schema. Otherwise, you need to ensure the 
producer's schema matches the message structure.
   
   Here's a similar example in Java:
   ```java
           PulsarClient client = PulsarClient.builder()
                   .serviceUrl("pulsar://localhost:6650")
                   .build();
   
           String schemaDef = "{\n" +
                   "  \"type\": \"record\",\n" +
                   "  \"name\": \"SchemaTest\",\n" +
                   "  \"fields\": [\n" +
                   "    { \"name\": \"userName\", \"type\": \"string\" },\n" +
                   "    { \"name\": \"userAge\", \"type\": \"int\" }\n" +
                   "  ]\n" +
                   "}";
   
           SchemaInfo schemaInfo = SchemaInfo.builder()
                   .name("SchemaTest")
                   .type(SchemaType.JSON)
                   .schema(schemaDef.getBytes())
                   .build();
   
           GenericSchema<GenericRecord> schema = Schema.generic(schemaInfo);
   
           Producer<GenericRecord> producer = client.newProducer(schema)
                   .topic("test-schema")
                   .create();
   
   
           GenericRecord record = schema.newRecordBuilder()
                   .set("notUserName", "Alice")
                   .set("notUserAge", 30)
                   .build();
   
           producer.send(record);
   
           System.out.println("Message sent!");
   
           producer.close();
           client.close();
   ```
   The message will be sent successfully without validating the schema.
   
   


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to