Bird
Raised Fist0

Given this Kafka producer code snippet, what will happen if the message does not match the registered schema?

medium📝 Predict Output Q4 of Q15
Kafka - Schema Registry
Given this Kafka producer code snippet, what will happen if the message does not match the registered schema?
props.put("schema.registry.url", "http://localhost:8081");
props.put("value.serializer", "io.confluent.kafka.serializers.KafkaAvroSerializer");
Producer producer = new KafkaProducer<>(props);
producer.send(new ProducerRecord<>("topic", invalidRecord));
AThe producer will automatically update the schema and send the message
BThe message will be sent without validation
CThe producer will throw a serialization exception and fail to send the message
DThe message will be sent but marked as invalid in the topic
Step-by-Step Solution
Solution:
  1. Step 1: Understand schema validation behavior

    If the message does not match the schema, the Avro serializer throws an exception during serialization.
  2. Step 2: Analyze options

    Only The producer will throw a serialization exception and fail to send the message correctly describes the failure; others incorrectly say message is sent or schema auto-updated.
  3. Final Answer:

    The producer will throw a serialization exception and fail to send the message -> Option C
  4. Quick Check:

    Invalid schema message = Serialization exception [OK]
Quick Trick: Invalid schema causes serialization exception in producer [OK]
Common Mistakes:
MISTAKES
  • Assuming schema auto-updates on invalid message
  • Thinking invalid messages are sent anyway
  • Believing invalid messages are marked but sent

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes