A. serviceB.consume should be called before process to receive messages
B. serviceA.publish should wait for serviceB.process to finish
C. serviceB.process() should be called after consume
D. No error; the code is correct
Solution
Step 1: Understand message consumption order
To process messages, the consumer must subscribe or consume from the queue before processing.
Step 2: Identify incorrect sequence
Calling serviceB.process() before consume means no messages are received yet, causing a logic error.
Final Answer:
serviceB.consume should be called before process to receive messages -> Option A
Quick Check:
Consume before processing = C [OK]
Hint: Consume messages before processing them [OK]
Common Mistakes:
Calling process before consuming messages
Expecting publish to wait for processing
Thinking code order does not matter
5. You are designing a microservices system where Service A must send a request to Service B and continue working without waiting for a response. Which communication pattern should you choose to ensure scalability and loose coupling?
hard
A. Direct database polling by Service A
B. Synchronous HTTP request with retries
C. Asynchronous messaging via a message queue
D. Tightly coupled RPC calls with blocking
Solution
Step 1: Analyze requirement for non-blocking communication
Service A must not wait for Service B's response, so asynchronous communication is needed.
Step 2: Choose scalable and loosely coupled pattern
Using a message queue allows Service A to send messages and continue, while Service B processes independently, supporting scalability and loose coupling.
Final Answer:
Asynchronous messaging via a message queue -> Option C
Quick Check:
Async messaging for non-blocking and scalability = A [OK]
Hint: Pick async messaging for non-blocking, scalable design [OK]