Dubbo's Adaptive Annotation Usage

First, let's introduce the Adaptive annotation:

@Adaptive: Provide parameters for generating Adaptive instances, the scope is on the class or method;

    Adaptive, literally means an adaptation, but it is actually a proxy, which means adapting the appropriate object to handle the request. Similar to the dynamic proxy of jdk, because the bottom layer of dubbo will use reflection a lot, for performance reasons, it will use javassist bytecode compilation by default to generate an adaptive to intercept all requests, and then it will dynamically delegate the appropriate provider based on the policy for processing.
The SPI interface will dynamically compile an adaptive to adapt the provider to process requests. Users can implement an adaptive by themselves, and only need to mark a provider with @adaptive, such as Dubbo's own AdaptiveExtensionFactory class.
For the scheme that compiles and generates Adaptive by default, you need to use @Adaptive to declare which methods on the interface are adaptive methods. If a method that has not been declared is requested, it will throw an exception that is not an adaptive method.

 

Below is the basic usage.

Adaptive annotations (annotations for adaptive extension points):

      The first: get the interface according to the default spi

    

 

The second: Adaptive annotation

        String[] {"key1", "key2"}

Get the interface according to key1 or key2

The third Adaptive annotation

If not set, the default is to use the dot-separated lowercase string of the Extension interface class name

    The default value for Ext3 is ext3

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326918862&siteId=291194637