KafkaMessageBus v4.2.3 KafkaMessageBus.Examples.SampleMessageData View Source

This is an example of how validator structs should be written.

The first step to defining a validator struct is to use the MessageDataType module as follows: use KafkaMessageBus.Messages.MessageData.MessageDataType

Structure: Validator structs are written as Ecto embedded_schemas. The user will define the schema using Ecto and will thereby specify the types and default values through the Ecto schema.

Factory function: Each message data struct will provide a new/1 function. One can create this function by copy/pasting the following line into the module definition: def new(%{} = messagedata), do: mapstruct(%__MODULE{}, message_data)

Validate function: Validation rules for each validation struct will be implemented by defining the schema's changeset/2 function. The additional function, validate_required_inclusion/2, is used to ensure that one of n fields is provided with the message data.

Link to this section Summary

Functions

This function is used to facilitate the definition of message data type's new/1 (factory) functions.

This is an example of the expected factory function. If the type you are creating this function for has embedded structs you will also want to create empty structs for those types too, as shown below.

Link to this section Functions

Link to this function

changeset(message_data, attrs \\ %{}) View Source

Link to this function

map_struct(struct, message_data) View Source

This function is used to facilitate the definition of message data type's new/1 (factory) functions.

This is an example of the expected factory function. If the type you are creating this function for has embedded structs you will also want to create empty structs for those types too, as shown below.