Disable register if registry disable register (#12579)
* Disable register if registry disable register * Fix tag * Fix tag
This commit is contained in:
parent
ea35f7ed5c
commit
25c2b3808a
|
|
@ -426,7 +426,25 @@ public abstract class ServiceConfigBase<T> extends AbstractServiceConfig {
|
|||
|
||||
public abstract boolean isUnexported();
|
||||
|
||||
/**
|
||||
* Export service to network
|
||||
*
|
||||
* @param register Whether register service to registry. If false, can be registered manually
|
||||
* through the {@link ServiceConfigBase#register(boolean)} API.
|
||||
*/
|
||||
public abstract void export(boolean register);
|
||||
|
||||
public abstract void register();
|
||||
/**
|
||||
* Register delay published service to registry.
|
||||
*/
|
||||
public final void register() {
|
||||
register(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register delay published service to registry.
|
||||
*
|
||||
* @param onlyDefault only register those services that export with configured register false
|
||||
*/
|
||||
public abstract void register(boolean onlyDefault);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,10 +57,10 @@ import java.beans.Transient;
|
|||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.TreeSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -99,6 +99,7 @@ import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_BIND;
|
|||
import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_REGISTRY;
|
||||
import static org.apache.dubbo.config.Constants.SCOPE_NONE;
|
||||
import static org.apache.dubbo.registry.Constants.REGISTER_KEY;
|
||||
import static org.apache.dubbo.registry.Constants.REGISTER_ORIGIN_KEY;
|
||||
import static org.apache.dubbo.remoting.Constants.BIND_IP_KEY;
|
||||
import static org.apache.dubbo.remoting.Constants.BIND_PORT_KEY;
|
||||
import static org.apache.dubbo.remoting.Constants.IS_PU_SERVER_KEY;
|
||||
|
|
@ -310,7 +311,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
public void register(boolean onlyDefault) {
|
||||
if (!this.exported) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -321,7 +322,9 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
|
|||
}
|
||||
|
||||
for (Exporter<?> exporter : exporters) {
|
||||
exporter.register();
|
||||
if (!onlyDefault || exporter.getInvoker().getUrl().getParameter(REGISTER_ORIGIN_KEY, true)) {
|
||||
exporter.register();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -813,6 +816,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
|
|||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private void doExportUrl(URL url, boolean withMetaData, boolean register) {
|
||||
if (!register) {
|
||||
url = url.addParameter(REGISTER_ORIGIN_KEY, url.getParameter(REGISTER_KEY, true));
|
||||
url = url.addParameter(REGISTER_KEY, false);
|
||||
}
|
||||
Invoker<?> invoker = proxyFactory.getInvoker(ref, (Class) interfaceClass, url);
|
||||
|
|
|
|||
|
|
@ -441,7 +441,7 @@ public class DefaultModuleDeployer extends AbstractDeployer<ModuleModel> impleme
|
|||
if (!sc.isExported()) {
|
||||
return;
|
||||
}
|
||||
sc.register();
|
||||
sc.register(true);
|
||||
}
|
||||
|
||||
private void unexportServices() {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ public interface Constants {
|
|||
String REGISTER_IP_KEY = "register.ip";
|
||||
|
||||
String REGISTER_KEY = "register";
|
||||
String REGISTER_ORIGIN_KEY = "register_origin";
|
||||
|
||||
String SUBSCRIBE_KEY = "subscribe";
|
||||
|
||||
|
|
|
|||
|
|
@ -61,12 +61,12 @@ import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
|
|||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_LOCAL_FILE_CACHE_ENABLED;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_EMPTY_ADDRESS;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_NOTIFY_EVENT;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_DESTROY_UNREGISTER_URL;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_READ_WRITE_CACHE_FILE;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_DELETE_LOCKFILE;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_EMPTY_ADDRESS;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_DELETE_LOCKFILE;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_DESTROY_UNREGISTER_URL;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_NOTIFY_EVENT;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_READ_WRITE_CACHE_FILE;
|
||||
import static org.apache.dubbo.common.constants.RegistryConstants.ACCEPTS_KEY;
|
||||
import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGORY;
|
||||
import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY;
|
||||
|
|
|
|||
Loading…
Reference in New Issue