문제 두보 해결 2.7.3 버전 ConfigCenterConfig 아폴로 통합 없음 제공자를 찾을 수없는

두보 2.7.3 통합 아폴로

문제 설명

두보 2.7.3 중앙 외부 구성의 구성을 지원하며, 따라서 단지 콩의 ConfigCenterConfig을 정의 할 필요가있다.

@EnableDubbo(scanBasePackages = {"com.slankka.cloud.dubbo"})
@Configuration
public class DubboConfig {
    @Bean
    public ConfigCenterConfig configCenterConfig() {
        ConfigCenterConfig configCenterConfig = new ConfigCenterConfig();
        configCenterConfig.setAddress("apollo.xxxxx.com:8080");
        configCenterConfig.setProtocol("apollo");
        configCenterConfig.setNamespace("dubbo");
        configCenterConfig.setGroup(null);
        return configCenterConfig;
    }
}

문제 :

  1. 아폴로는 메타를 찾을 수 없습니다.
  2. 두보 제공자를 찾을 수 없습니다

솔루션

  1. 아폴로, 아폴로의 항아리 메타를 찾을 수없는, 아폴로 코어 구성 파일은 분명히 PRO.meta = "apollo.xxxxx.com:8080"를 선언합니다. 이 문제는 발생
apollo.bootstrap.enabled = false

이 구성을 준수 할 경우, 필요 증가

apollo.meta=apollo.xxxxx.com:8080
  1. 후자는 예를 들어, 버전 번호를 따르지 않은 경우, com.xxx.xxx.service : 1.2.0, 다음 버전이 정의되지 않은 두보는 공급자, 로그 인터페이스에 대해 자세히 살펴 찾을 수 없습니다.
    문제는 자리의 정의, 두보는 클래스 ReferenceBean BeanPostProcessor를 만들 때 시작하면서 때문에, 초기에 시작하고 = 거짓 apollo.bootstrap.enabled 것입니다.
    두보는 버전을 찾을 수 없습니다,이 IRExecutionService에게 해당 Bean 클래스를 만들 수 있지만 그 이상 따라 잡을를 먹었다. 버전이 구성되지 않은 동일합니다.
apollo.bootstrap.enabled = false

@Reference(version = "${job.service.version}", retries = 0, lazy = true)
private IRExecutionService executionService;

당신은 매우 간단하지만 앞서 초기화 스위치의 아폴로에 너무 의존 해결하려면 이유는, 너무 늦게 두보 ConfigCenterConfig 버전을 읽을에서 사용할 수 없거나.

당신이 apollo.bootstrap.enabled = 거짓, 올바른 행동 두보 주장하면 어떻게 할까?

package io.github.slankka.dubbo-apollo.server.config;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.Configuration;
import org.apache.dubbo.common.config.Environment;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ConfigCenterConfig;
import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor;
import org.apache.dubbo.configcenter.DynamicConfiguration;
import org.apache.dubbo.configcenter.DynamicConfigurationFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.InjectionMetadata;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.env.PropertySource;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static org.apache.dubbo.common.config.ConfigurationUtils.parseProperties;

/**
 * Project: dubbo-apollo
 *
 * @author slankka on 2019/8/29.
 */
@ConditionalOnProperty(name = "apollo.bootstrap.enabled", havingValue = "false", matchIfMissing = true)
@Component(value = ReferenceAnnotationBeanPostProcessor.BEAN_NAME)
public class ReferencedAnnotationPatch extends ReferenceAnnotationBeanPostProcessor {

    private ApplicationContext myContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        myContext = applicationContext;
        super.setApplicationContext(applicationContext);
    }

    @Override
    protected Object doGetInjectedBean(AnnotationAttributes attributes, Object bean, String beanName,
                                       Class<?> injectedType,
                                       InjectionMetadata.InjectedElement injectedElement) throws Exception {
        eagerInitConfigCenter();
        Configuration configuration = Environment.getInstance().getConfiguration();

        List<PropertySource<?>> propertySources = new ArrayList<>();
        propertySources.add(new PropertySource<Configuration>("dubboConfigCenter", configuration) {
            @Override
            public Object getProperty(String name) {
                return configuration.getProperty(name);
            }
        });
        PropertySourcesPlaceholdersResolver propertySourcesPlaceholdersResolver = new PropertySourcesPlaceholdersResolver(propertySources);

        for (String attribute : attributes.keySet()) {
            Object stringAttr = attributes.get(attribute);
            if (stringAttr instanceof String) {
                Object value = propertySourcesPlaceholdersResolver.resolvePlaceholders(attributes.getString(attribute));
                attributes.put(attribute, value);
            }
        }

        return super.doGetInjectedBean(attributes, bean, beanName, injectedType, injectedElement);
    }

    private void eagerInitConfigCenter() {
        ConfigCenterConfig configCenter = myContext.getBean(ConfigCenterConfig.class);
        if (configCenter.isValid()) {
            if (configCenter.checkOrUpdateInited()) {
                configCenter.refresh();

                URL url = configCenter.toUrl();
                DynamicConfigurationFactory factories = ExtensionLoader
                        .getExtensionLoader(DynamicConfigurationFactory.class)
                        .getExtension(url.getProtocol());
                DynamicConfiguration dynamicConfiguration = factories.getDynamicConfiguration(url);
                String configContent = dynamicConfiguration.getProperties(configCenter.getConfigFile(), configCenter.getGroup());

                ApplicationConfig application = myContext.getBean(ApplicationConfig.class);
                String appGroup = application.getName();
                String appConfigContent = null;
                if (StringUtils.isNotEmpty(appGroup)) {
                    appConfigContent = dynamicConfiguration.getProperties
                            (StringUtils.isNotEmpty(configCenter.getAppConfigFile()) ? configCenter.getAppConfigFile() : configCenter.getConfigFile(),
                                    appGroup
                            );
                }
                try {
                    Environment.getInstance().setConfigCenterFirst(configCenter.isHighestPriority());
                    Environment.getInstance().updateExternalConfigurationMap(parseProperties(configContent));
                    Environment.getInstance().updateAppExternalConfigurationMap(parseProperties(appConfigContent));
                } catch (IOException e) {
                    throw new IllegalStateException("Failed to parse configurations from Config Center.", e);
                }
            }
        }
    }
}

ReferenceAnnotationBeanPostProcessor는 @Reference 주석 자리가 해결 될 수 있도록, 두보의 문제를 해결하기 위해이 시간 때문에 콩이 ConfigCenterConfig 된, 그래서 ConfigCenter 일찍 출발을 할 수 있습니다.
이 자리 배치 스페이스 ( "보행")가 있음에 유의 안쪽.

마지막으로, 작은 문제

사용자 정의 네임 스페이스, 그는 읽을 것인지가 존재하고 천천히 시작하지 않기 때문에, 빈 두보 아폴로의 공간 창출을 제시 시작 속도를 빠르게하기 위해, 그래서 두보는, 두보이 아폴로의 네임 스페이스를 읽기 기본 설정됩니다.

추천

출처www.cnblogs.com/slankka/p/11431324.html