Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How is the Dubbo Provider Filter chain constructed

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how the Dubbo Provider Filter chain is constructed". In the daily operation, I believe that many people have doubts about how the Dubbo Provider Filter chain is constructed. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how the Dubbo Provider Filter chain is constructed". Next, please follow the editor to study!

The construction of the Filter chain on the provider side is built in the initialization process. We know that the initialization process will definitely go to the method org.apache.dubbo.remoting.transport.netty4.NettyServer#doOpen. You can make a breakpoint in this method, and then start the provider service. The call stack information is as follows:

Judging from the method org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper#export code in the call stack, buildInvokerChain builds the Filter chain of provider:

Public Exporter export (Invoker invoker) throws RpcException {

If (UrlUtils.isRegistry (invoker.getUrl () {

Return protocol.export (invoker)

}

/ / invoker is the code that calls the corresponding method directly, JavassistProxyFactory

Return protocol.export (buildInvokerChain (invoker, SERVICE_FILTER_KEY, CommonConstants.PROVIDER))

}

From the above code, buildInvokerChain is the logic for building the Filter chain, which is loaded by SPI. The FIlter configuration path is META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter, and the configuration content is as follows:

Echo=org.apache.dubbo.rpc.filter.EchoFilter

Generic=org.apache.dubbo.rpc.filter.GenericFilter

Genericimpl=org.apache.dubbo.rpc.filter.GenericImplFilter

Token=org.apache.dubbo.rpc.filter.TokenFilter

Accesslog=org.apache.dubbo.rpc.filter.AccessLogFilter

Activelimit=org.apache.dubbo.rpc.filter.ActiveLimitFilter

Classloader=org.apache.dubbo.rpc.filter.ClassLoaderFilter

Context=org.apache.dubbo.rpc.filter.ContextFilter

Consumercontext=org.apache.dubbo.rpc.filter.ConsumerContextFilter

Exception=org.apache.dubbo.rpc.filter.ExceptionFilter

Executelimit=org.apache.dubbo.rpc.filter.ExecuteLimitFilter

Deprecated=org.apache.dubbo.rpc.filter.DeprecatedFilter

Compatible=org.apache.dubbo.rpc.filter.CompatibleFilter

Timeout=org.apache.dubbo.rpc.filter.TimeoutFilter

Note that the Filter of the above configuration includes Consumer and Provider. Initializing provider only uses the Filter configuration on the provider side. The specific Filter implementation class will distinguish between PROVIDER and CONSUMER through group. The corresponding buildInvokerChain logic is as follows:

Private static Invoker buildInvokerChain (final Invoker invoker, String key, String group) {

Invoker last = invoker

List filters = ExtensionLoader.getExtensionLoader (Filter.class) .getActivateExtension (invoker.getUrl (), key, group)

If (! filters.isEmpty ()) {

For (int I = filters.size ()-1; I > = 0; iMel -) {

Final Filter filter = filters.get (I)

Final Invoker next = last

Last = new Invoker () {

@ Override

Public Result invoke (Invocation invocation) throws RpcException {

Return filter.invoke (next, invocation)

}

}

}

}

Return last

}

The buildInvokerChain logic builds the Filter filter chain in order. Since the FIlter implementation class does not set the order of @ Activate annotations, the order of the Filter filter chain is the order in which the META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter file is configured, which should be noted.

At this point, the study on "how to build the Dubbo Provider Filter chain" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report