title: How to configure and receiveAndConvert jSON payload into domain Object in Spring Boot and RabbitMQ
body: <p>Recently I have been having a keen interest on Microservice Architecture using Spring Boot. My implementation has two Spring boot applications;</p>
  
  <p><strong>Application One</strong> receives requests from a RESTful API, converts and sends jSON payload to a <strong>RabbitMQ queueA</strong>. </p>
  
  <p><strong>Application Two</strong>, has subscribed to <strong>queueA</strong>, receives the jSON payload(Domain Object User) and is supposed to activate a service within Application Two eg. send email to a user.</p>
  
  <p>Using no XML in my <strong>Application Two</strong> configuration, how do I configure a converter that will convert the jSON payload received from RabbitMQ into a Domain Object User.</p>
  
  <p>Below are snippets from Spring Boot configurations on Application Two</p>
  
  <p><strong>Application.class</strong></p>
  
  <pre><code>@SpringBootApplication
  @EnableRabbit
  public class ApplicationInitializer implements CommandLineRunner {
  
      final static String queueName = "user-registration";
  
      @Autowired
      RabbitTemplate rabbitTemplate;
  
      @Autowired
      AnnotationConfigApplicationContext context;
  
      @Bean
      Queue queue() {
          return new Queue(queueName, false);
      }
  
      @Bean
      TopicExchange topicExchange() {
          return new TopicExchange("user-registrations");
      }
  
      @Bean
      Binding binding(Queue queue, TopicExchange exchange) {
          return BindingBuilder.bind(queue).to(exchange).with(queueName);
      }
  
      @Bean
      SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
          SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
          container.setConnectionFactory(connectionFactory);
          container.setQueueNames(queueName);
          container.setMessageListener(listenerAdapter);
          return container;
      }
  
      public static void main(String[] args) {
          SpringApplication.run(ApplicationInitializer.class, args);
      }
  
      @Override
      public void run(String... args) throws Exception {
          System.out.println("Waiting for messages...");
      }
  
  }
  </code></pre>
  
  <p><strong>TestService.java</strong></p>
  
  <pre><code>@Component
  public class TestService {
  
      /**
       * This test verifies whether this consumer receives message off the user-registration queue
       */
      @RabbitListener(queues = "user-registration")
      public void testReceiveNewUserNotificationMessage(User user) {
          // do something like, convert payload to domain object user and send email to this user
      }
  
  }
  </code></pre>