Bird
0
0

You want to send a JSON object as a message using RabbitTemplate. Which step is necessary before calling convertAndSend?

hard📝 Application Q8 of 15
Spring Boot - Messaging
You want to send a JSON object as a message using RabbitTemplate. Which step is necessary before calling convertAndSend?
AConfigure a message converter like Jackson2JsonMessageConverter
BManually convert the object to JSON string before sending
CSet the exchange to null to enable JSON conversion
DUse send() method instead of convertAndSend()
Step-by-Step Solution
Solution:
  1. Step 1: Understand message conversion for objects

    RabbitTemplate needs a message converter to convert objects to JSON automatically.
  2. Step 2: Identify correct converter for JSON

    Jackson2JsonMessageConverter is the standard converter to serialize objects to JSON format.
  3. Final Answer:

    Configure a message converter like Jackson2JsonMessageConverter -> Option A
  4. Quick Check:

    JSON messages require Jackson2JsonMessageConverter [OK]
Quick Trick: Set Jackson2JsonMessageConverter to send JSON objects [OK]
Common Mistakes:
  • Manually converting objects instead of using converter
  • Passing null exchange to enable conversion
  • Using send() which does not convert objects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes