parent
33694c860f
commit
fd053ade57
@ -0,0 +1,48 @@
|
||||
package com.ruoyi.common.log.mq.rabbit;
|
||||
|
||||
import org.springframework.amqp.core.ReturnedMessage;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 操作日志消息队列-回调函数
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Configuration
|
||||
public class RabbitLogCallback {
|
||||
|
||||
@Bean
|
||||
public RabbitTemplate createRabbitTemplate(ConnectionFactory connectionFactory){
|
||||
RabbitTemplate rabbitTemplate = new RabbitTemplate();
|
||||
rabbitTemplate.setConnectionFactory(connectionFactory);
|
||||
//设置开启Mandatory,才能触发回调函数,无论消息推送结果怎么样都强制调用回调函数
|
||||
rabbitTemplate.setMandatory(true);
|
||||
|
||||
rabbitTemplate.setConfirmCallback(new RabbitTemplate.ConfirmCallback() {
|
||||
@Override
|
||||
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
|
||||
System.out.println("ConfirmCallback: "+"相关数据:"+correlationData);
|
||||
System.out.println("ConfirmCallback: "+"确认情况:"+ack);
|
||||
System.out.println("ConfirmCallback: "+"原因:"+cause);
|
||||
}
|
||||
});
|
||||
|
||||
rabbitTemplate.setReturnsCallback(new RabbitTemplate.ReturnsCallback() {
|
||||
@Override
|
||||
public void returnedMessage(ReturnedMessage returnedMessage) {
|
||||
System.out.println("ReturnCallback: "+"消息:"+returnedMessage.getMessage());
|
||||
System.out.println("ReturnCallback: "+"回应码:"+returnedMessage.getReplyCode());
|
||||
System.out.println("ReturnCallback: "+"回应信息:"+returnedMessage.getReplyText());
|
||||
System.out.println("ReturnCallback: "+"交换机:"+returnedMessage.getExchange());
|
||||
System.out.println("ReturnCallback: "+"路由键:"+returnedMessage.getRoutingKey());
|
||||
}
|
||||
});
|
||||
|
||||
return rabbitTemplate;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.ruoyi.common.log.service;
|
||||
|
||||
import com.ruoyi.system.api.domain.SysOperLog;
|
||||
|
||||
/**
|
||||
* 调用日志服务接口
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ILogService {
|
||||
|
||||
/**
|
||||
* 保存系统日志记录
|
||||
*/
|
||||
public void saveSysLog(SysOperLog sysOperLog);
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.ruoyi.common.log.service.impl;
|
||||
|
||||
import com.ruoyi.common.log.service.ILogService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.system.api.RemoteLogService;
|
||||
import com.ruoyi.system.api.domain.SysOperLog;
|
||||
|
||||
/**
|
||||
* 异步调用日志服务
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Primary
|
||||
@Service
|
||||
public class AsyncLogService implements ILogService
|
||||
{
|
||||
@Autowired
|
||||
private RemoteLogService remoteLogService;
|
||||
|
||||
/**
|
||||
* 保存系统日志记录
|
||||
*/
|
||||
@Async
|
||||
@Override
|
||||
public void saveSysLog(SysOperLog sysOperLog)
|
||||
{
|
||||
remoteLogService.saveLog(sysOperLog, SecurityConstants.INNER);
|
||||
}
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.ruoyi.common.log.service.AsyncLogService,\
|
||||
com.ruoyi.common.log.service.impl.AsyncLogService,\
|
||||
com.ruoyi.common.log.service.impl.RabbitLogService,\
|
||||
com.ruoyi.common.log.mq.rabbit.RabbitLogDirect,\
|
||||
com.ruoyi.common.log.mq.rabbit.RabbitLogCallback,\
|
||||
com.ruoyi.common.log.aspect.LogAspect
|
||||
|
Loading…
Reference in new issue