Spring-boot Integrated Dubbo:spring-boot-dubbo-starter

Source: Internet
Author: User

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
    1. For the consumer or provider of the service, use the Dubbo built-in annotation @service or @reference to declare
    2. 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
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.