Now, we should modify our Java Producer to send messages in Avro format. First, it is important to mention that in Avro there are two types of messages:
- Specific records: The file with the Avro schema (avsc) is sent to a specific Avro command to generate the corresponding Java classes.
- Generic records: In this approach, a data structure similar to a map dictionary is used. This means that you set and get the fields by their names and you must know their corresponding types. This option is not type-safe, but it offers much more flexibility than the other, and here the versions are much easier to manage over time. In this example, we will use this approach.
Before we start with the code, remember that in the last chapter we added the library to support Avro to our Kafka client. If you recall, the build.gradle file has a special repository with all this libraries...