AOP的失效情况通常是因为事务类自己调用导致被AOP代理的方法没有实现接口导致。
客户端的熔断降级可以通过@SentinelResource(value = "getAddressBookDetail", fallback = "detailFallback", blockHandler = "detailBlockHandler")这种注解实现。
不过也因此,openfien的调用需要再包装一层
package com.jzo2o.orders.manager.service.client;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.jzo2o.api.customer.AddressApi;
import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import com.jzo2o.orders.manager.service.impl.OrdersCreateServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
-
@author Mr.M
-
@version 1.0
-
@description 调用customer的客户端类
-
@date 2023/12/3 21:27
*/
@Component
@Slf4j
public class CustomerClient {@Resource
private AddressApi addressApi;@SentinelResource(value = "getAddressBookDetail", fallback = "detailFallback", blockHandler = "detailBlockHandler")
public AddressBookResDTO detail(Long id) {
log.error("根据id查询地址簿,id:{}", id);
// 调用其他微服务方法
AddressBookResDTO detail = addressApi.detail(id);
return detail;
}//执行异常走
public AddressBookResDTO detailFallback(Long id, Throwable throwable) {
log.error("非限流、熔断等导致的异常执行的降级方法,id:{},throwable:", id, throwable);
return null;
}//熔断后的降级逻辑
public AddressBookResDTO detailBlockHandler(Long id, BlockException blockException) {
log.error("触发限流、熔断时执行的降级方法,id:{},blockException:", id, blockException);
return null;
}
}
分布式事务锁可以通过redission实现