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).
The code follows the following flow:
- 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.
- If the message is of type
AttunityMetadataMessage
, a user-definedhandleMetadataMessage
method is called with the proper casting on the message. - If the message is of type
AttunityDataMessage
, a user-definedhandleDataMessage
method is called with the proper casting. - 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.
- If decoding failed, an appropriate message is also sent, together with the exception details from the decoder.