event_serializer v2.0.3 EventSerializer.SchemaRegistryCache

This service is responsible to fetch the schemas from Schema Registry and cache theirs names and ids.

That result will be saved in a cache so we can re utilize in the EventSerializer.Publisher

We start the server using the start_link/0 function:

EventSerializer.SchemaRegistryServer.start_link()

Then we can fetch the id of the schema using the fetch/1 function.

EventSerializer.SchemaRegistryServer.fetch(“topic-key”)

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor

This function returns the schema id for a given schema_name

This function fetches the schema ids from the Schema Registry

This function starts the server and perform the cache

Link to this section Functions

Link to this function child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function fetch(schema_name)

This function returns the schema id for a given schema_name

On application boot the key and value schema ids are saved in this GenServers state, so here we can quickly retrive them

Example

iex(1)> SchemaRegistryCache.fetch("a_known_matching_schema_key")
2

iex(2)> SchemaRegistryCache.fetch("a_unknown_schema_key")
nil
Link to this function fetch_schemas()

This function fetches the schema ids from the Schema Registry.

The :avlizer_confluent is used to fetch and cache the schema body. make_encoder function is resposible to do that. More information in the docs: https://github.com/klarna/avlizer/blob/master/src/avlizer_confluent.erl#L97

The return of this function is a list of maps containing the schema name and id, which will be cached for future requests.

The return will be like this:

Example

[

%{id: 13, name: "topic-value"},
%{id: 12, name: "topic-key"}

]

This function starts the server and perform the cache.

Link to this function key_schema_name(topic)
Link to this function value_schema_name(topic)