auto detect proxy type (#12232)

* auto detect proxy type

* auto detect proxy type
This commit is contained in:
icodening 2023-05-05 16:18:31 +08:00 committed by GitHub
parent 0724e94da7
commit c5f8ce6478
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 5 deletions

View File

@ -0,0 +1,25 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.model;
/**
* Marker interface implemented by all stub. Used to detect
* whether objects are Dubbo-generated stub.
*/
public interface DubboStub {
}

View File

@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
{{#deprecated}}
@java.lang.Deprecated
{{/deprecated}}
public interface {{interfaceClassName}} {
public interface {{interfaceClassName}} extends org.apache.dubbo.rpc.model.DubboStub {
static final String JAVA_SERVICE_NAME = "{{packageName}}.{{serviceName}}";
static final String SERVICE_NAME = "{{commonPackageName}}.{{serviceName}}";

View File

@ -27,7 +27,7 @@ import java.util.Map;
import java.util.function.BiConsumer;
import java.util.concurrent.CompletableFuture;
public interface {{interfaceClassName}} {
public interface {{interfaceClassName}} extends org.apache.dubbo.rpc.model.DubboStub {
String JAVA_SERVICE_NAME = "{{packageName}}.{{serviceName}}";
String SERVICE_NAME = "{{commonPackageName}}.{{serviceName}}";

View File

@ -51,7 +51,7 @@ public static final String SERVICE_NAME = "{{packageName}}.{{serviceName}}";
/**
* Code generated for Dubbo
*/
public interface I{{serviceName}} {
public interface I{{serviceName}} extends org.apache.dubbo.rpc.model.DubboStub {
static Class<?> clazz = init();

View File

@ -51,7 +51,7 @@ public static final String SERVICE_NAME = "{{packageName}}.{{serviceName}}";
/**
* Code generated for Dubbo
*/
public interface I{{serviceName}} {
public interface I{{serviceName}} extends org.apache.dubbo.rpc.model.DubboStub {
static Class<?> clazz = init();

View File

@ -22,7 +22,7 @@ package {{packageName}};
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public interface {{interfaceClassName}} {
public interface {{interfaceClassName}} extends org.apache.dubbo.rpc.model.DubboStub {
String JAVA_SERVICE_NAME = "{{packageName}}.{{serviceName}}";

View File

@ -43,6 +43,7 @@ import org.apache.dubbo.rpc.cluster.support.ClusterUtils;
import org.apache.dubbo.rpc.cluster.support.registry.ZoneAwareCluster;
import org.apache.dubbo.rpc.model.AsyncMethodInfo;
import org.apache.dubbo.rpc.model.ConsumerModel;
import org.apache.dubbo.rpc.model.DubboStub;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.apache.dubbo.rpc.model.ModuleServiceRepository;
import org.apache.dubbo.rpc.model.ScopeModel;
@ -264,6 +265,12 @@ public class ReferenceConfig<T> extends ReferenceConfigBase<T> {
if (!this.isRefreshed()) {
this.refresh();
}
//auto detect proxy type
String proxyType = getProxy();
if (StringUtils.isBlank(proxyType)
&& DubboStub.class.isAssignableFrom(interfaceClass)) {
setProxy(CommonConstants.NATIVE_STUB);
}
// init serviceMetadata
initServiceMetadata(consumer);