apache/pulsar-client-go

Pulsar Client Go Schema Registry to save scheme use for both Producer and Consumer

ThinhLe30 opened this issue · 2 comments

I'm using Avro schema and here is the example code to create a producer and consumer to send/receive messages:

//Create producer and send message
producer, err := client.CreateProducer(pulsar.ProducerOptions{
    Topic:  "my-topic",
    Schema: pulsar.NewAvroSchema(exampleSchemaDef, nil),
})

msgId, err := producer.Send(context.Background(), &pulsar.ProducerMessage{
    Value: avroExampleStruct{
       ID:   10,
       Name: "avroExampleStruct",
  },
})

//Create Consumer and receive a message
consumer, err := client.Subscribe(pulsar.ConsumerOptions{
    Topic:            "my-topic",
    Schema:           pulsar.NewAvroSchema(exampleSchemaDef, nil),
    SubscriptionName: "my-sub",
    Type:             pulsar.Shared,
})
message, err := consumer.Receive(context.Background())

The thing is the Schema option is hard-code and what if the producer changes the schema properties, then the consumer can not effect -> error. How can I get a Schema Registry to save the schema using for both producer and consumer

Pulsar has the builtin schema registry: https://pulsar.apache.org/docs/next/schema-overview/
Schema evolution outlines how the system behaves when the producer or consumer modifies the schema.

Similar to the Java client, it's necessary to set up the schema when creating producers and consumers. This schema serves as a writing schema for producers and a reading schema for consumers.

The difference is that we could use the POJO type to generate the schema definition for the Java client. Unfortunately, the Go client doesn't currently have this feature.

Thanks a lot @RobertIndie Ro.