Bird
0
0

Identify the error in this Kafka CQRS command handler code:

medium📝 Debug Q6 of 15
Kafka - Event-Driven Architecture
Identify the error in this Kafka CQRS command handler code:
producer.send('orders-commands', {'orderId': 10, 'action': 'update'})
consumer.subscribe(['orders-commands'])
for msg in consumer:
    process_command(msg.value)
    producer.send('orders-events', {'orderId': 10, 'status': 'updated'})
AThe event topic name is incorrect
BThe consumer should not subscribe to the commands topic
Cprocess_command should not be called inside the loop
DThe producer should send events to 'orders-commands' topic
Step-by-Step Solution
Solution:
  1. Step 1: Understand roles of topics in CQRS

    Commands topic is for receiving commands; the consumer here is correctly subscribed to commands to process them.
  2. Step 2: Check for error in subscription

    Actually, subscribing to commands topic is correct for command handler; no error here.
  3. Step 3: Re-examine options

    The consumer should not subscribe to the commands topic says consumer should not subscribe to commands topic, which is false. The producer should send events to 'orders-commands' topic says producer sends events to commands topic, which is false because events should go to events topic.
  4. Final Answer:

    The producer should send events to 'orders-commands' topic -> Option D
  5. Quick Check:

    Events must be sent to event topic, not commands [OK]
Quick Trick: Events go to event topics, not command topics [OK]
Common Mistakes:
  • Sending events to commands topic
  • Confusing consumer subscriptions
  • Misnaming topics

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes