最近,我对使用Spring Boot的微服务架构产生了浓厚的兴趣.我的实现有两个Spring启动应用程序;
应用的一个接收请求从一个RESTful API,转换并发送有效载荷JSON到的RabbitMQ queueA.
应用程序二,已订阅queueA,接收jSON有效负载(域对象用户),并且应该激活Application Two中的服务,例如.向用户发送电子邮件.
在我的Application Two配置中不使用XML ,如何配置将从RabbitMQ接收的jSON有效负载转换为域对象用户的转换器.
以下是Application Two上Spring Boot配置的摘录
Application.class
@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 …Run Code Online (Sandbox Code Playgroud)