event_serializer v2.0.3 EventSerializer.Encoder

This module is resposible to encode the message sent to a Kafka topic.

Link to this section Summary

Functions

Elixir’s erlavro library don’t put some bytes used by Confluent for the Schema Registry. So, in order to publish using AVRO properly, both the key and values, after being encoded to avro must be prepended with the bytes expected by confluent

Link to this section Functions

Link to this function call(schema_name, event)

Elixir’s erlavro library don’t put some bytes used by Confluent for the Schema Registry. So, in order to publish using AVRO properly, both the key and values, after being encoded to avro must be prepended with the bytes expected by confluent:

<<0>> <> <> <> encoded_key_by_erlavro <<0>> <> <> <> encoded_message_by_erlavro

This function uses the avlizer_confluent from erlang to encode the schema.

The make_encoder makes a request to download the schema with the given schema_id and result is cached by this library. The first request to download the schema is made by a gen_server EventSerializer.SchemaRegistryCache which is initialized before the app starts.

The second step will encode the message into a binary format:

<<0, 0, 0, 0, 13, 142, 229, 41, 48, 50, 48, 49, 56, 45 ....>>

Then we prepend the schema_id in message.