# Sample Code Snippet

`AttunityMessageDecoder messageDecoder` – Previously defined and initialized with a proper schema locator.

`KafkaConsumer consumer` – Previously defined and initialized, and subscribed to some Kafka topic(s).

![](https://help.qlik.com/en-US/replicate/November2025/Content/Resources/Images/Replicate/Avro/avro_code_sample.jpg)

The code follows the following flow:

1. A Kafka consumer polls for messages. After the consumer has read the messages, each message is sent to the message decoder for decoding and message type verification.
2. If the message is of type `AttunityMetadataMessage`, a user-defined ` handleMetadataMessage  `method is called with the proper casting on the message.
3. If the message is of type `AttunityDataMessage`, a user-defined `handleDataMessage` method is called with the proper casting.
4. If an unknown message class is returned (i.e. the SDK supports more class types than the customer's code), an appropriate message is sent.
5. If decoding failed, an appropriate message is also sent, together with the exception details from the decoder.