ダボ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;
}
}
問題:
- アポロは、メタを見つけることができません。
- ダボプロバイダが見つかりません
ソリューション
- アポロは、メタ、アポロのjarファイルを見つけることができない、アポロ・コア・コンフィギュレーション・ファイルは明らかにPRO.meta =「apollo.xxxxx.com:8080」を宣言します。この問題は、中に発生します
apollo.bootstrap.enabled = false
この設定に準拠したい場合は、必要性が増加します
apollo.meta=apollo.xxxxx.com:8080
- 後者は、例えば、バージョン番号に従わなかった場合、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 = falseを、正しい行動ダボを主張する場合はどのように行うには?
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はダボの動作を修正することができ、この時間ので、豆ConfigCenterConfigがあったので、@Referenceコメントプレースホルダを解決できるように、ConfigCenterは早く始めましょう。
このプレースホルダは、名前空間(「ダボ」)に配置されていることに注意してください。内部。
最後に、小さな問題
ダボは、カスタム名前空間ならば、彼は、彼らが存在しないため、読んで減速し始めるだろう、このアポロの名前空間読んでダボをデフォルトなので、起動速度を高速化するために、空のダボにアポロの名前空間の作成を示唆している。します