springAOP编程整合rabbitmq
时间:2018-09-22 14:23:02
收藏:0
阅读:274
创建拦截方法的前置通知和后置通知相关类
rabbitmq模板配置
上述配置成功后每次调用userService.checkLogin()方法时,
都会在方法调用前向指定队列发送消息,方法执行完到指定队列消费消息
还有就是spring 和rabbitmq不兼容会导致AOP方法抛出异常
@Component
public class AopAspect {
@Autowired
private AmqpTemplate template1;
public void beforeAdvice(JoinPoint joinPoint) {
String s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
template1.convertAndSend("defaultQueue",s);
System.out.println("向消息队列发送消息" + s);
}
public void afterAdvice(JoinPoint joinPoint){
Object o = template1.receiveAndConvert("defaultQueue");
System.out.println("向队列消费消息" + o.toString());
}
}
springAOP的配置
原文:http://blog.51cto.com/12165865/2178963
评论(0)