Loki
3 years ago
5 changed files with 74 additions and 24 deletions
@ -0,0 +1,2 @@ |
|||||||
|
tenantInFilter=dubbo.config.Infilter |
||||||
|
tenantOutFilter=dubbo.config.OutFilter |
@ -0,0 +1,28 @@ |
|||||||
|
package dubbo.config; |
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil; |
||||||
|
import cn.iocoder.yudao.framework.common.exception.ErrorCode; |
||||||
|
import cn.iocoder.yudao.framework.common.exception.ServiceException; |
||||||
|
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; |
||||||
|
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.apache.dubbo.common.constants.CommonConstants; |
||||||
|
import org.apache.dubbo.common.extension.Activate; |
||||||
|
import org.apache.dubbo.rpc.*; |
||||||
|
|
||||||
|
@Slf4j |
||||||
|
@Activate(group = CommonConstants.PROVIDER) |
||||||
|
public class Infilter implements Filter{ |
||||||
|
|
||||||
|
@Override |
||||||
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { |
||||||
|
String tenantId = invocation.getAttachment("tenantId"); |
||||||
|
if (ObjectUtil.isNotEmpty(tenantId)){ |
||||||
|
TenantContextHolder.setTenantId(Long.valueOf(tenantId)); |
||||||
|
}else{ |
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR); |
||||||
|
} |
||||||
|
|
||||||
|
return invoker.invoke(invocation); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
package dubbo.config; |
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
||||||
|
import org.apache.dubbo.common.constants.CommonConstants; |
||||||
|
import org.apache.dubbo.common.extension.Activate; |
||||||
|
import org.apache.dubbo.rpc.*; |
||||||
|
|
||||||
|
@Activate(group = CommonConstants.CONSUMER) |
||||||
|
public class OutFilter implements Filter { |
||||||
|
@Override |
||||||
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { |
||||||
|
Long tenantId = TenantContextHolder.getTenantId(); |
||||||
|
invocation.setAttachment("tenantId",tenantId.toString()); |
||||||
|
return invoker.invoke(invocation); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue