热卖商品
新闻详情
Apollo —— OpenAPI调用_hxyascx的博客-CSDN博客
来自 : CSDN技术社区
发布时间:2021-03-25
引入依赖
需要引入两个依赖 1、集成apollo的依赖。2、调用apollo修改数据的openAPI的依赖。
!-- https://mvnrepository.com/artifact/com.ctrip.framework.apollo/apollo-client -- dependency groupId com.ctrip.framework.apollo /groupId artifactId apollo-client /artifactId version 1.6.0 /version /dependency !-- https://mvnrepository.com/artifact/com.ctrip.framework.apollo/apollo-openapi -- dependency groupId com.ctrip.framework.apollo /groupId artifactId apollo-openapi /artifactId version 1.6.0 /version /dependency增加配置代码
增加调用Apollo的客户端类ApolloOpenApiClient 用来在程序中动态的修改Apollo的值。这里需要token 稍后介绍
Configuration EnableApolloConfigpublic class ApolloAutoConfig { String portalUrl http://10.253.1.32:18082 ; // portal url String token 7782fbb0bde803c978fc79adb37839efb1527414 ; // 申请的token Bean public AppConfig appConfig() { return new AppConfig(); Bean public ApolloOpenApiClient apolloOpenApiClient() { ApolloOpenApiClient client ApolloOpenApiClient.newBuilder() .withPortalUrl(portalUrl) .withToken(token) .build(); return client;public class AppConfig { Value( ${test.demo} ) private String demo; public String getDemo() { return demo; public void setDemo(String demo) { this.demo demo;设置Apollo的配置
apollo: meta: http://10.253.1.32:18080# meta: http://39.106.161.250:8080 bootstrap: enabled: true namespaces: MRFRESH.CityConfig测试类
RequestMapping( /test ) RestControllerpublic class TestController { Autowired private AppConfig appConfig; Autowired private ApolloOpenApiClient client; private String appId mrfresh-common ; GetMapping( /demo ) public String hello() { return appConfig.getDemo(); //新增配置 PostMapping( /add ) public Object addParam() { OpenItemDTO openItemDTO new OpenItemDTO(); openItemDTO.setKey( timeout ); openItemDTO.setValue( 100 ); openItemDTO.setComment( 超时时间 ); openItemDTO.setDataChangeCreatedBy( apollo ); OpenItemDTO item client.createItem(appId, DEV , default , MRFRESH.CityConfig , openItemDTO); return JSON.toJSONString(item); //修改配置 PostMapping( /update ) public Object updateParam() { OpenItemDTO openItemDTO new OpenItemDTO(); openItemDTO.setKey( timeout ); openItemDTO.setValue( 200 ); openItemDTO.setComment( 超时时间 ); openItemDTO.setDataChangeCreatedBy( apollo ); client.createOrUpdateItem(appId, DEV , default , MRFRESH.CityConfig , openItemDTO); return JSON.toJSONString(openItemDTO); //发布配置 PostMapping( /release ) public Object releaseParam() { NamespaceGrayDelReleaseDTO namespaceGrayDelReleaseDTO new NamespaceGrayDelReleaseDTO(); namespaceGrayDelReleaseDTO.setReleaseTitle( 2019-03-27 17:38 release ); namespaceGrayDelReleaseDTO.setReleaseComment( test release ); namespaceGrayDelReleaseDTO.setReleasedBy( apollo ); OpenReleaseDTO openReleaseDTO client.publishNamespace(appId, DEV , default , MRFRESH.CityConfig , namespaceGrayDelReleaseDTO); return JSON.toJSONString(openReleaseDTO); //获取名称空间下所有的配置 GetMapping( /namespace ) public Object getAllNameSpace() { return JSON.toJSONString(client.getNamespace(appId, DEV , default , MRFRESH.CityConfig ));获取token
页面分为上下两个部分 第三方应用ID是指 需要调用OpenAPI动态修改apollo配置的第三方应用ID app.id apollo-demo。下面被管理的Appid是指需要修改的 Apollo中的配置信息。例如下面的配置。
本文链接: http://apolloapi.immuno-online.com/view-733039.html
发布于 : 2021-03-25
阅读(0)
最新动态
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
品牌分类
Pharmaceutical
联络我们
服务热线:4000-520-616
(限工作日9:00-18:00)
QQ :1570468124
手机:18915418616