Bird
0
0

Given this Kafka CQRS code snippet:

medium📝 Predict Output Q4 of 15
Kafka - Event-Driven Architecture
Given this Kafka CQRS code snippet:
commands_topic = 'orders-commands'
queries_topic = 'orders-queries'

# Command handler writes event
producer.send(commands_topic, {'orderId': 1, 'action': 'create'})

# Query handler reads events
consumer.subscribe([queries_topic])

# What will the query handler receive?
AAn error because consumer subscribed to wrong topic
BThe 'create' command message sent by the producer
CAll messages from both topics automatically
DNo messages, because commands and queries use separate topics
Step-by-Step Solution
Solution:
  1. Step 1: Analyze topic usage

    The producer sends commands to 'orders-commands' topic, but the consumer subscribes to 'orders-queries' topic.
  2. Step 2: Understand message flow

    Since these are separate topics, the query handler will not receive messages sent to the commands topic.
  3. Final Answer:

    No messages, because commands and queries use separate topics -> Option D
  4. Quick Check:

    Separate topics mean no cross messages [OK]
Quick Trick: Commands and queries use different topics, no overlap [OK]
Common Mistakes:
  • Assuming consumer gets all messages from all topics
  • Thinking subscription to queries topic gets commands
  • Believing Kafka merges topics automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes