Why do you write this gadget?
If you have used Spring-boot to provide Dubbo services, I believe there are a lot of "uncomfortable" places in use. Since spring boot is used, there is no XML configuration where annotations can be used, which is spring-boot-style. A joke, really means that spring-boot is suitable for some simple, independent services, a large system is not suitable for the use of spring-boot to develop. On the contrary, Spring-boot is suitable for simple service construction. Most of the methods on the Web use XML configuration, using @import annotations to introduce XML configuration.
How to use
- For the consumer or provider of the service, use the Dubbo built-in annotation @service or @reference to declare
- Configure the relevant parameters of Dubbo in Application.properties/yml, for example, the following is a simple consumer configuration
dubbo:application: name:lizo-Consumer registry: Address:zookeeper:// localhost:12181
- Use @enabledubbo (basepackages = "xxx.xxx.xxx") on the configuration class to turn on automatic configuration of Dubbo
After the above 3 steps, you can complete the configuration of the Dubbo, is not very spring-bootstyle
Dubbo-filter
Dubbo has many extensions, where filter is used to compare one more. But it's not convenient to use. It would be nice if you could simply declare a bean just like the spring boot definition of Spring MVC filter. Well, that's actually it.
@Bean providerfilter providerfilter () { returnnew providerfilter (); } Static class extends Abstractdubboproviderfiltersupport { public Result Invoke ( invoker<?> Invoker , invocation invocation) { System.out.println ("Providerfilter"); return Invoker.invoke (invocation); } }
More customized requirements, you can use Dubbo's @activate annotations to customize the filter, so you can
@Bean customfilter customfilter () {return NewCustomfilter (); } @Activate (Group=Constants.provider)Static classCustomfilterextendsAbstractdubbofiltersupport { PublicResult Invoke (invoker<?> Invoker, invocation invocation)throwsrpcexception {System.out.println ("ProviderFilter2"); returnInvoker.invoke (invocation); } PublicFilter getdefaultextension () {return This; } }
If interested
Source code and its demo address:
- Code Cloud: Https://git.oschina.net/null_584_3382/spring-dubbo-parent
- Github:https://github.com/athlizo/spring-dubbo-parent
Final description
- Dubbo the underlying code is not developed, just the encapsulation on which it is based.
- Multiple registration sources are not supported
- Have bugs or have code optimization suggestions welcome Feedback
Spring-boot Integrated Dubbo:spring-boot-dubbo-starter