完成Dubbo/Dubbox的插件以及测试
This commit is contained in:
parent
7bbe9ceb07
commit
da9192cfd3
|
|
@ -34,6 +34,12 @@
|
|||
<version>3.0.0.RELEASE</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aop</artifactId>
|
||||
<version>3.0.0.RELEASE</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jaxrs</artifactId>
|
||||
|
|
@ -88,20 +94,28 @@
|
|||
<version>0.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!--
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbox</artifactId>
|
||||
<version>2.8.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
-->
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbox</artifactId>
|
||||
<version>2.8.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo</artifactId>
|
||||
<version>2.5.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
|
|
@ -140,12 +154,12 @@
|
|||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>bintray-wu-sheng-sky-walking-repository</id>
|
||||
<name>wu-sheng-sky-walking-repository</name>
|
||||
<url>https://api.bintray.com/maven/wu-sheng/skywalking/com.ai.cloud.skywalking-dubbo-plugin/;publish=1</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<repository>
|
||||
<id>bintray-wu-sheng-sky-walking-repository</id>
|
||||
<name>wu-sheng-sky-walking-repository</name>
|
||||
<url>https://api.bintray.com/maven/wu-sheng/skywalking/com.ai.cloud.skywalking-dubbo-plugin/;publish=1</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
package com.ai.cloud.skywalking.plugin;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.extension.ExtensionLoader;
|
||||
import com.alibaba.dubbo.rpc.*;
|
||||
import net.bytebuddy.implementation.bind.annotation.Argument;
|
||||
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DubboFilterBuildInterceptor {
|
||||
|
||||
@RuntimeType
|
||||
public <T> Object intercept(
|
||||
@Argument(0) final Invoker invoker,
|
||||
@Argument(1) final String key,
|
||||
@Argument(2) final String group)
|
||||
throws Exception {
|
||||
final URL newURL = invoker.getUrl().addParameter(key, "skywalking$enhanceFilter");
|
||||
Invoker<T> last = invoker;
|
||||
List<Filter> filters = ExtensionLoader.getExtensionLoader(Filter.class).getActivateExtension(newURL, key, group);
|
||||
if (filters.size() > 0) {
|
||||
for (int i = filters.size() - 1; i >= 0; i--) {
|
||||
final Filter filter = filters.get(i);
|
||||
final Invoker<T> next = last;
|
||||
last = new Invoker<T>() {
|
||||
public Class<T> getInterface() {
|
||||
return invoker.getInterface();
|
||||
}
|
||||
|
||||
public URL getUrl() {
|
||||
return newURL;
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
return invoker.isAvailable();
|
||||
}
|
||||
|
||||
public Result invoke(Invocation invocation) throws RpcException {
|
||||
return filter.invoke(next, invocation);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
invoker.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return invoker.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
return last;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.ai.cloud.skywalking.plugin;
|
||||
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.plugin.boot.BootException;
|
||||
import com.ai.cloud.skywalking.plugin.boot.BootPluginDefine;
|
||||
import com.alibaba.dubbo.rpc.Invoker;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.dynamic.ClassFileLocator;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
|
||||
import net.bytebuddy.implementation.MethodDelegation;
|
||||
import net.bytebuddy.pool.TypePool;
|
||||
|
||||
import static com.ai.cloud.skywalking.plugin.PluginBootstrap.CLASS_TYPE_POOL;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
public class DubboPluginDefine extends BootPluginDefine {
|
||||
|
||||
private static final String interceptorClassName = "com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper";
|
||||
|
||||
@Override
|
||||
protected void boot() throws BootException {
|
||||
if (!AuthDesc.isAuth()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TypePool.Resolution resolution = CLASS_TYPE_POOL.describe(interceptorClassName);
|
||||
DynamicType.Builder<?> newClassBuilder = new ByteBuddy()
|
||||
.rebase(resolution.resolve(),
|
||||
ClassFileLocator.ForClassLoader.ofClassPath());
|
||||
|
||||
newClassBuilder = newClassBuilder.method(named("buildInvokerChain")
|
||||
.and(takesArguments(Invoker.class, String.class, String.class)))
|
||||
.intercept(MethodDelegation.to(new DubboFilterBuildInterceptor()));
|
||||
|
||||
newClassBuilder
|
||||
.name(interceptorClassName)
|
||||
.make()
|
||||
.load(ClassLoader.getSystemClassLoader(),
|
||||
ClassLoadingStrategy.Default.INJECTION).getLoaded();
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1 @@
|
|||
swEnhanceFilter=com.ai.cloud.skywalking.plugin.dubbo.SWDubboEnhanceFilter
|
||||
skywalking$enhanceFilter=com.ai.cloud.skywalking.plugin.dubbo.SWDubboEnhanceFilter
|
||||
|
|
@ -0,0 +1 @@
|
|||
com.ai.cloud.skywalking.plugin.DubboPluginDefine
|
||||
|
|
@ -1,15 +1,29 @@
|
|||
package com.ai.cloud.skywalking.plugin.test.dubbo.consumer;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.TracingBootstrap;
|
||||
import com.ai.cloud.skywalking.plugin.test.dubbo.interfaces.IDubboInterA;
|
||||
import com.ai.skywalking.testframework.api.TraceTreeAssert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class DubboConsumer {
|
||||
|
||||
|
||||
@Test
|
||||
public void test() throws InvocationTargetException, NoSuchMethodException, ClassNotFoundException, IllegalAccessException {
|
||||
TracingBootstrap
|
||||
.main(new String[]{"com.ai.cloud.skywalking.plugin.test.dubbo.consumer.DubboConsumer"});
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:consumer/dubbo-consumer.xml");
|
||||
IDubboInterA dubboInterA = context.getBean(IDubboInterA.class);
|
||||
dubboInterA.doBusiness("AAAAA");
|
||||
Thread.sleep(10000000L);
|
||||
TraceTreeAssert.assertEquals(new String[][]{
|
||||
{"0", "dubbo://127.0.0.1:20880/com.ai.cloud.skywalking.plugin.test.dubbo.interfaces.IDubboInterA.doBusiness(String)", ""}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,19 @@
|
|||
package com.ai.cloud.skywalking.plugin.test.dubbo.impl;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.TracingBootstrap;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class DubboStart {
|
||||
|
||||
@Test
|
||||
public void test() throws InvocationTargetException, NoSuchMethodException, ClassNotFoundException, IllegalAccessException {
|
||||
TracingBootstrap
|
||||
.main(new String[]{"com.ai.cloud.skywalking.plugin.test.dubbo.impl.DubboStart"});
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
ClassPathXmlApplicationContext classPathXmlApplicationContext = new
|
||||
ClassPathXmlApplicationContext("classpath*:provider/dubbo-provider.xml");
|
||||
|
|
|
|||
|
|
@ -1,24 +1,36 @@
|
|||
package com.ai.cloud.skywalking.plugin.test.dubbox283.consumer;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.TracingBootstrap;
|
||||
import com.ai.cloud.skywalking.plugin.dubbox.bugfix.below283.BugFixAcitve;
|
||||
import com.ai.cloud.skywalking.plugin.test.dubbox283.interfaces.IDubboxRestInterA;
|
||||
import com.ai.cloud.skywalking.plugin.test.dubbox283.interfaces.param.DubboxRestInterAParameter;
|
||||
import com.ai.skywalking.testframework.api.TraceTreeAssert;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class DubboxRestConsumer {
|
||||
private static final Log logger = LogFactory.getLog(DubboxRestConsumer.class);
|
||||
|
||||
@Test
|
||||
public void test() throws InvocationTargetException, NoSuchMethodException, ClassNotFoundException, IllegalAccessException {
|
||||
TracingBootstrap
|
||||
.main(new String[]{"com.ai.cloud.skywalking.plugin.test.dubbox283.consumer.DubboxRestConsumer"});
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException {
|
||||
new BugFixAcitve();
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:consumer/dubbox283-consumer.xml");
|
||||
IDubboxRestInterA dubboxRestInterA = context.getBean(IDubboxRestInterA.class);
|
||||
dubboxRestInterA.doBusiness(new DubboxRestInterAParameter("AAAAA"));
|
||||
Thread.sleep(10000000L);
|
||||
TraceTreeAssert.assertEquals(new String[][]{
|
||||
{"0", "rest://127.0.0.1:20880/com.ai.cloud.skywalking.plugin.test.dubbox283.interfaces.IDubboxRestInterA.doBusiness(DubboxRestInterAParameter)", ""}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,20 @@
|
|||
package com.ai.cloud.skywalking.plugin.test.dubbox283.consumer;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.TracingBootstrap;
|
||||
import com.ai.cloud.skywalking.plugin.dubbox.bugfix.below283.BugFixAcitve;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class DubboxRestStart {
|
||||
|
||||
@Test
|
||||
public void test() throws InvocationTargetException, NoSuchMethodException, ClassNotFoundException, IllegalAccessException {
|
||||
TracingBootstrap
|
||||
.main(new String[]{"com.ai.cloud.skywalking.plugin.test.dubbox283.consumer.DubboxRestStart"});
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
new BugFixAcitve();
|
||||
ClassPathXmlApplicationContext classPathXmlApplicationContext = new
|
||||
|
|
|
|||
|
|
@ -1,22 +1,34 @@
|
|||
package com.ai.cloud.skywalking.plugin.test.dubbox284.consumer;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.TracingBootstrap;
|
||||
import com.ai.cloud.skywalking.plugin.test.dubbox283.interfaces.param.DubboxRestInterAParameter;
|
||||
import com.ai.cloud.skywalking.plugin.test.dubbox284.interfaces.IDubboxRestInterA;
|
||||
import com.ai.skywalking.testframework.api.TraceTreeAssert;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class DubboxRestConsumer {
|
||||
private static final Log logger = LogFactory.getLog(DubboxRestConsumer.class);
|
||||
|
||||
@Test
|
||||
public void test() throws InvocationTargetException, NoSuchMethodException, ClassNotFoundException, IllegalAccessException {
|
||||
TracingBootstrap
|
||||
.main(new String[]{"com.ai.cloud.skywalking.plugin.test.dubbox284.consumer.DubboxRestConsumer"});
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:consumer/dubbox284-consumer.xml");
|
||||
IDubboxRestInterA dubboxRestInterA = context.getBean(IDubboxRestInterA.class);
|
||||
dubboxRestInterA.doBusiness(new DubboxRestInterAParameter("AAAAA"));
|
||||
Thread.sleep(10000000L);
|
||||
TraceTreeAssert.assertEquals(new String[][]{
|
||||
{"0", "rest://127.0.0.1:20880/com.ai.cloud.skywalking.plugin.test.dubbox284.interfaces.IDubboxRestInterA.doBusiness(DubboxRestInterAParameter)", ""}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,20 @@
|
|||
package com.ai.cloud.skywalking.plugin.test.dubbox284.consumer;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.TracingBootstrap;
|
||||
import com.ai.cloud.skywalking.plugin.dubbox.bugfix.below283.BugFixAcitve;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class DubboxRestStart {
|
||||
|
||||
@Test
|
||||
public void test() throws InvocationTargetException, NoSuchMethodException, ClassNotFoundException, IllegalAccessException {
|
||||
TracingBootstrap
|
||||
.main(new String[]{"com.ai.cloud.skywalking.plugin.test.dubbox284.consumer.DubboxRestStart"});
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
new BugFixAcitve();
|
||||
ClassPathXmlApplicationContext classPathXmlApplicationContext = new
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
<dubbo:application name="skywalking-consumer"/>
|
||||
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
|
||||
<dubbo:consumer filter="swEnhanceFilter"/>
|
||||
<dubbo:reference id="dubboInterA" interface="com.ai.cloud.skywalking.plugin.test.dubbo.interfaces.IDubboInterA"
|
||||
url="dubbo://192.168.1.108:20880"/>
|
||||
url="dubbo://127.0.0.1:20880"/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
<dubbo:application name="skywalking-consumer"/>
|
||||
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
|
||||
<dubbo:consumer filter="swEnhanceFilter"/>
|
||||
<dubbo:reference id="dubboxRestInterA" interface="com.ai.cloud.skywalking.plugin.test.dubbox283.interfaces.IDubboxRestInterA"
|
||||
url="rest://192.168.1.108:20880"/>
|
||||
url="rest://127.0.0.1:20880"/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -7,9 +7,8 @@
|
|||
|
||||
<dubbo:application name="skywalking-consumer"/>
|
||||
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
|
||||
<dubbo:consumer filter="swEnhanceFilter"/>
|
||||
<dubbo:reference id="dubboxRestInterA"
|
||||
interface="com.ai.cloud.skywalking.plugin.test.dubbox284.interfaces.IDubboxRestInterA"
|
||||
url="rest://192.168.1.108:20880"/>
|
||||
url="rest://127.0.0.1:20880"/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
<dubbo:protocol name="dubbo" port="20880"/>
|
||||
|
||||
<dubbo:provider filter="swEnhanceFilter"/>
|
||||
<bean id="dubboInterA" class="com.ai.cloud.skywalking.plugin.test.dubbo.impl.DubboInterAImpl"/>
|
||||
|
||||
<dubbo:service interface="com.ai.cloud.skywalking.plugin.test.dubbo.interfaces.IDubboInterA" ref="dubboInterA"/>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
<dubbo:application name="skywalking-dubbo-rest-provider"/>
|
||||
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
|
||||
<dubbo:protocol name="rest" port="20880" server="tomcat"/>
|
||||
<dubbo:provider filter="swEnhanceFilter"/>
|
||||
<bean id="dubboxRestInterA" class="com.ai.cloud.skywalking.plugin.test.dubbox283.impl.DubboxRestInterAImpl"/>
|
||||
<dubbo:service interface="com.ai.cloud.skywalking.plugin.test.dubbox283.interfaces.IDubboxRestInterA"
|
||||
ref="dubboxRestInterA"/>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
<dubbo:application name="skywalking-dubbo-rest-provider"/>
|
||||
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
|
||||
<dubbo:protocol name="rest" port="20880" server="tomcat"/>
|
||||
<dubbo:provider filter="swEnhanceFilter"/>
|
||||
<bean id="dubboxRestInterA" class="com.ai.cloud.skywalking.plugin.test.dubbox284.impl.DubboxRestInterAImpl"/>
|
||||
<dubbo:service interface="com.ai.cloud.skywalking.plugin.test.dubbox284.interfaces.IDubboxRestInterA"
|
||||
ref="dubboxRestInterA"/>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ skywalking.application_code=test
|
|||
skywalking.auth_system_env_name=SKYWALKING_RUN
|
||||
#skywalking数据编码
|
||||
skywalking.charset=UTF-8
|
||||
skywalking.auth_override=true
|
||||
|
||||
#是否打印数据
|
||||
buriedpoint.printf=true
|
||||
|
|
@ -27,11 +28,8 @@ sender.max_send_length=20000
|
|||
#当没有Sender时,尝试获取sender的等待周期
|
||||
sender.retry_get_sender_wait_interval=2000
|
||||
|
||||
|
||||
|
||||
|
||||
#最大消费线程数
|
||||
consumer.max_consumer=2
|
||||
consumer.max_consumer=0
|
||||
#消费者最大等待时间
|
||||
consumer.max_wait_time=5
|
||||
#发送失败等待时间
|
||||
|
|
|
|||
Loading…
Reference in New Issue