1、编写javaagent用于对dubbo invoke方案做切面处理
public class Agent {
private static final Logger logger = LogManager.getLogger(Agent.class);
public static void premain(String arguments, Instrumentation instrumentation) {
// 匹配被拦截方法
agentBuilder.type(named("com.alibaba.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker"))
.transform(
new AgentBuilder.Transformer() {
@Override
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription type, ClassLoader classLoader, JavaModule module) {
return builder.method(named("invoke")).intercept(
MethodDelegation.withDefaultConfiguration().to(
new CommonInterceptor(classLoader, "com.example.dubbomock.agent.DubboInvokeInterceptor")));
}
}
).installOn(instrumentation);
//注解方式l配置依赖的dubbo interface方式拦截
agentBuilder.type(named("com.alibaba.dubbo.config.ReferenceConfig"))
.transform(
//拦截器没有call 其他类加载器加载的类,无需做classloader转换
new AgentBuilder.Transformer() {
@Override
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription type, ClassLoader classLoader, JavaModule module) {
return builder.method(named("createProxy")).intercept(
MethodDelegation.to(DubboStartInterceptor.class));
}
}
).installOn(instrumentation);
}
网友评论