数据同步保证流程:三步
一、生产者和消费者 分别导入依赖+yml配置
<!--amqp-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
spring:
rabbitmq:
host: IP
port: 5672
username: 用户名
password: 密码
virtual-host: /
二、生产者工作:
1、定义交换机、队列和RoutingKey。
2、在表现层中自动装配rabbitTemplate,相应的业务中,添加生产消息convertAndSend
三、消费者工作:
1、定义交换机、队列和RoutingKey。
2、可以使用Bean的方式或者使用注解的方式(本次使用Bean)
使用bean的形式 --->MqConfig: 交换机、队列、绑定关系:(BindingBuilder.bind().to().with())并加载成配置类@Configuration
3、添加Listener监听器定义为Component:
@RabbitListener(queues = ) 写对应的业务逻辑:
这里es不能直接访问数据库只能通过暴露的接口与es库交互
es流程:准备request
准备DSL
发送请求