Reset the schema cache?
Thank you so much for this library. Would it be possible to add a method to the Schema Registry Client to reset the cache, or replace an existing value in the case of a schema evolution? Right now the cache is an unexported field so there is no way to access it.
Thank You!
- Eric
Can you provide an actual example of your issue?
Thanks for your response. Looking at the library more closely I'm realizing it's mostly built around having your schemas defined as Go Struct Types, meaning you have to update your code and re-deploy your service when there is a schema evolution of a topic.
If I wanted to avoid hardcoding Go Types I suppose I could do something like this:
func TestConvertToAvroWithoutType(t *testing.T) {
// Pretend call to Schema Registry to get Schema
// schema, err := sr.client.GetSchema(ctx, id)
schema, err := avro.Parse(`{
"type": "record",
"name": "simple",
"namespace": "org.hamba.avro",
"fields" : [
{"name": "a", "type": "int"},
{"name": "b", "type": "string"},
{"name": "c", "type": "string"}
]
}`)
require.NoError(t, err)
buf := bytes.NewBuffer([]byte{})
enc, err := avro.NewEncoder(schema.String(), buf)
require.NoError(t, err)
obj := map[string]any{
"a": 1,
"b": "bar",
"c": "eric",
"d": "bernie",
}
err = enc.Encode(obj)
data := buf.Bytes()
fmt.Println(data) // [2 6 98 97 114 8 101 114 105 99]
}
The above example only serializes fields a,b and c, and ignores d. If I include d in the schema I get the complete byte array: [2 6 98 97 114 8 101 114 105 99 12 98 101 114 110 105 101]
In this scenario it would be beneficial to be able to update the cache
// RemoveSchemaCache Code added by Eric Abis
func (c *Client) RemoveSchemaCache(id int) {
c.cache.Delete(id)
}
With all of that said, it's a bit of work to properly implement the above example, and I most likely will stick to the hardcoded definitions for the immediate future.
Thanks, Eric
In the Confluent Schema Registry, a Schema and its ID become an immutable pair, meaning to update the schema, it will get a new id, so it is unclear to me how removing an ID from the registry clients cache helps with updating the schema? Perhaps I am missing something?
Oh duh you are right! So in the case of a schema evolution I would pull the latest schema_id for the subject, and update the id.
Sorry about all of this!
- Eric