Apollo quick start SampleApp demo Java
2022/7/7 1:21:23
本文主要是介绍Apollo quick start SampleApp demo Java,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<!--配置中心--> <dependency> <groupId>com.ctrip.framework.apollo</groupId> <artifactId>apollo-client</artifactId> <version>1.7.0</version> </dependency
pom文件引入jar包
src/main/resources/META-INF/app.properties
app.id=SampleApp # value=800 默认值 apollo.meta=http://localhost:8080 # 启动日志 # 09:01:06.752 [Apollo-RemoteConfigLongPollService-1] WARN com.ctrip.framework.apollo.internals.RemoteConfigLongPollService - Long polling failed, will retry in 16 seconds. appId: SampleApp, cluster: default, namespaces: application, long polling url: null, reason: Get config services failed from http://localhost:80801/services/config?appId=SampleApp&ip=192.168.137.1 [Cause: Could not complete get operation [Cause: port out of range:80801]]
package com.redis.demo.apollo; import com.ctrip.framework.apollo.Config; import com.ctrip.framework.apollo.ConfigChangeListener; import com.ctrip.framework.apollo.ConfigService; import com.ctrip.framework.apollo.model.ConfigChange; import com.ctrip.framework.apollo.model.ConfigChangeEvent; import com.ctrip.framework.apollo.spring.annotation.ApolloConfig; import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig; import org.springframework.context.annotation.Configuration; //@Configuration //@EnableApolloConfig public class AplloTest { // @ApolloConfig // private Config config; //inject config for namespace application public static void main(String[] args) { Config config = ConfigService.getAppConfig(); //config instance is singleton for each namespace and is never null String someKey = "timeout"; String someDefaultValue = "800"; String value = config.getProperty(someKey, someDefaultValue); System.out.println("value=" + value); config.addChangeListener(new ConfigChangeListener() { @Override public void onChange(ConfigChangeEvent changeEvent) { System.out.println("Changes for namespace " + changeEvent.getNamespace()); for (String key : changeEvent.changedKeys()) { ConfigChange change = changeEvent.getChange(key); System.out.println(String.format("Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s", change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getChangeType())); } } }); /** * Changes for namespace application * Found change - key: timeout, oldValue: 300, newValue: 3001, changeType: MODIFIED */ try { //阻塞 Thread.sleep(600000); } catch (InterruptedException e) { e.printStackTrace(); } } }
这篇关于Apollo quick start SampleApp demo Java的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?