消费者在调用提供者时, 需要从多个提供者中选择符合条件的提供者, 其中涉及路由. 如何SPI自己的实现的路由
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.8</version>
</dependency>
package com.infuq.consumer;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.cluster.Router;
import org.apache.dubbo.rpc.cluster.RouterFactory;
@Activate
public class NotFoundMethodRouterFactory implements RouterFactory {
@Override
public Router getRouter(URL url) {
return new NotFoundMethodRouter();
}
}
package com.infuq.consumer;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.cluster.router.AbstractRouter;
import java.util.List;
public class NotFoundMethodRouter extends AbstractRouter {
@Override
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws org.apache.dubbo.rpc.RpcException {
return invokers;
}
}
文件内容
method=com.infuq.consumer.NotFoundMethodRouterFactory