alibaba / dubbo-spring-boot-starter

Dubbo Spring Boot Starter
Apache License 2.0
2.1k stars 745 forks source link

怎么通过配置过滤掉dubbo默认的filter #53

Closed gosenme closed 6 years ago

gosenme commented 6 years ago

DubboProperties里面支持的配置太少,怎么通过配置过滤掉dubbo默认的filter

xionghuiCoder commented 6 years ago

DubboProperties里面是一些provider和consumer的公共配置,其它配置可在注解@Service(provider端)和@Reference(consumer端)里面配置。

codefromthecrypt commented 6 years ago

Is the @Service annotation's filter property is actually used? I looked at the source code for dubbo and it doesn't seem to use it. Were you able to get this to work?

xionghuiCoder commented 6 years ago

@adriancole hi, @Service annotation's filter property is inited in com.alibaba.dubbo.config.AbstractConfig#appendAnnotation, line 435. It works already in dubbo 2.6.0.

codefromthecrypt commented 6 years ago

thanks. please ignore me on this one. I think I have a misunderstanding about how filter lifecycle works. I have found manually that a setter in trace filter was never called https://github.com/openzipkin/sleuth-webmvc-example/compare/add-dubbo-tracing

codefromthecrypt commented 6 years ago

I guess I'd like to externalize the filter config as opposed to hard-code it on the annotation

@chickenlj mentioned to me this:

 XML looks like this:

<!-- default timeout and filter for all services -->
<dubbo:consumer timeout="5000" filter="tracing" />
And annotation or spring boot, use .properties instead, for example:

dubbo.consumer.filter="tracing"

I tried in spring boot's properties file, even in a separate dubbo.properties file. Seems like filter should be something that we can do in spring boot style somehow (change without require user's code to change), ex via spring boot properties or autoconfiguration..

codefromthecrypt commented 6 years ago

sorry forgot to mention above was @chickenlj

codefromthecrypt commented 6 years ago

PS please hold an hour I was using a stale version of spring-cloud-sleuth.

We had to change sleuth as dubbo requires the bean name to exact match the extension name, so we changed sleuth to make sure it is exactly the same. I will update instructions on my end, and summarize progress in an hour.

codefromthecrypt commented 6 years ago

ok so right now, as far as I can tell, there is no way to use spring boot (application.properties or autoconfig) to assign a global filter. The only way is external to spring boot, ex via a dubbo.properties file

dubbo.provider.filter=tracing
dubbo.consumer.filter=tracing

This works, but the problem is that in spring boot you will not see this and it won't be intuitive. For example if I hit the /autoconfig endpoint it will not know about this properties file.

It would be nice to be able to define a bean like this:

@GlobalFilter @Bean Filter tracing(Tracing tracing) {
  TracingFilter result = new TracingFilter();
  result.setTracing(tracing);
  return tracing;
}

and have the above as the same as if it were set by properties "dubbo.provider.filter=tracing" and "dubbo.consumer.filter=tracing". However, I noticed that the extension loader for filter happens before hand because the filter itself is registered in meta-inf. In other words the statically initialized filter works instead.

For this reason, the simplest way out could just be allowing the spring boot starter here to define

spring.dubbo.provider.filter=tracing
spring.dubbo.consumer.filter=tracing

As long as spring is at least in control of the property names, we should be able to automatically insert the word tracing with spring-cloud-sleuth.

Does this make sense?

mercyblitz commented 6 years ago

@adriancole Please switch to this starter : https://github.com/dubbo/dubbo-spring-boot-project , which is official starter, thanks!

codefromthecrypt commented 6 years ago

@mercyblits I have been told both are official, but I suppose dubbo is the more official one now (due to apache I guess?)

mercyblitz commented 6 years ago

@adriancole yes, https://github.com/dubbo/dubbo-spring-boot-project is more better :D

xionghuiCoder commented 6 years ago

Duplicate of #72