第一步:配置队列
第二步:确认队列是否创建,登陆到rabbitMq的web管理界面
第三步:对show-cloud-users-service添加相应对依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
第四步:添加mq处理类,也就是队列监听
package org.go.show.users.rabitMqHandler;
import lombok.extern.slf4j.Slf4j;
import org.go.show.common.constants.LogQueue;
import org.go.show.users.i.AccountService;
import org.go.show.users.pojo.Account;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* 从mq队列消费日志数据
*
*
*/
@Component
@Slf4j
public class RabitMqHandler {
@Value("${goshow.log.logServiceBean:logServiceDBImpl}")
String logServiceBean;
@Autowired
AccountService accountService;
/**
* 监听帐套删除队列
*
* @param accountId
*/
@RabbitHandler
@RabbitListener(queues = LogQueue.DEL_ACCOUNT_QUEUE) // 监听队列
public void delAccountHandler(String accountId) {
try {
accountService.delAccountRelInfo(accountId);
} catch (Exception e) {
log.error("删除帐套操作,日志:{},异常:{}", accountId, e);
}
}
}
第五步:实现关联信息的删除操作。