From 73cda20ae0c45456aa51e4b9c4a60d4cfaae801a Mon Sep 17 00:00:00 2001 From: mercyblitz Date: Thu, 4 Oct 2018 01:04:17 +0800 Subject: [PATCH 01/23] Polish spring-cloud-incubator/spring-cloud-alibaba#34 : Initialize spring-cloud-alibaba-nacos-config-server module --- pom.xml | 1 + spring-cloud-alibaba-dependencies/pom.xml | 13 ++- .../pom.xml | 63 ++++++++++++++ .../NacosConfigServerAutoConfiguration.java | 45 ++++++++++ .../NacosEnvironmentRepository.java | 85 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 3 + .../bootstrap/NacosConfigServerBootstrap.java | 37 ++++++++ .../src/test/resources/application.properties | 2 + 8 files changed, 246 insertions(+), 3 deletions(-) create mode 100644 spring-cloud-alibaba-nacos-config-server/pom.xml create mode 100644 spring-cloud-alibaba-nacos-config-server/src/main/java/org/springframework/cloud/alibaba/nacos/config/server/NacosConfigServerAutoConfiguration.java create mode 100644 spring-cloud-alibaba-nacos-config-server/src/main/java/org/springframework/cloud/alibaba/nacos/config/server/environment/NacosEnvironmentRepository.java create mode 100644 spring-cloud-alibaba-nacos-config-server/src/main/resources/META-INF/spring.factories create mode 100644 spring-cloud-alibaba-nacos-config-server/src/test/java/org/springframework/cloud/alibaba/nacos/config/server/bootstrap/NacosConfigServerBootstrap.java create mode 100644 spring-cloud-alibaba-nacos-config-server/src/test/resources/application.properties diff --git a/pom.xml b/pom.xml index a8388a1ec..8eb156b61 100644 --- a/pom.xml +++ b/pom.xml @@ -82,6 +82,7 @@ spring-cloud-starter-alibaba spring-cloud-starter-alicloud spring-cloud-alicloud-oss + spring-cloud-alibaba-nacos-config-server diff --git a/spring-cloud-alibaba-dependencies/pom.xml b/spring-cloud-alibaba-dependencies/pom.xml index 2ff41fded..dd34a46fb 100644 --- a/spring-cloud-alibaba-dependencies/pom.xml +++ b/spring-cloud-alibaba-dependencies/pom.xml @@ -18,17 +18,26 @@ 0.1.1 3.1.0 - 0.2.1 + 0.2.2-SNAPSHOT + com.alibaba.nacos nacos-client ${nacos.version} + + + com.alibaba.nacos + nacos-config + ${nacos.version} + + + com.alibaba.csp sentinel-core @@ -136,8 +145,6 @@ - - diff --git a/spring-cloud-alibaba-nacos-config-server/pom.xml b/spring-cloud-alibaba-nacos-config-server/pom.xml new file mode 100644 index 000000000..eb5b48f4a --- /dev/null +++ b/spring-cloud-alibaba-nacos-config-server/pom.xml @@ -0,0 +1,63 @@ + + + + org.springframework.cloud + spring-cloud-alibaba + 0.2.0.BUILD-SNAPSHOT + ../pom.xml + + 4.0.0 + + org.springframework.cloud + spring-cloud-alibaba-nacos-config-server + + + + + + com.alibaba.nacos + nacos-config + + + + + org.springframework.cloud + spring-cloud-config-server + + + + + org.springframework.boot + spring-boot-starter + true + + + + org.springframework.boot + spring-boot-starter-actuator + true + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.cloud + spring-cloud-test-support + test + + + + + \ No newline at end of file diff --git a/spring-cloud-alibaba-nacos-config-server/src/main/java/org/springframework/cloud/alibaba/nacos/config/server/NacosConfigServerAutoConfiguration.java b/spring-cloud-alibaba-nacos-config-server/src/main/java/org/springframework/cloud/alibaba/nacos/config/server/NacosConfigServerAutoConfiguration.java new file mode 100644 index 000000000..42461f239 --- /dev/null +++ b/spring-cloud-alibaba-nacos-config-server/src/main/java/org/springframework/cloud/alibaba/nacos/config/server/NacosConfigServerAutoConfiguration.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cloud.alibaba.nacos.config.server; + +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.cloud.alibaba.nacos.config.server.environment.NacosEnvironmentRepository; +import org.springframework.cloud.config.server.EnableConfigServer; +import org.springframework.cloud.config.server.config.ConfigServerAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; + +/** + * Nacos Config Server Auto-Configuration + * + * @author Mercy + * @since 0.2.0 + */ +@ConditionalOnClass(EnableConfigServer.class) // If class of @EnableConfigServer is present in class-path +@ComponentScan(basePackages = { + "com.alibaba.nacos.config.server", +}) +@AutoConfigureBefore(ConfigServerAutoConfiguration.class) +public class NacosConfigServerAutoConfiguration { + + @Bean + public NacosEnvironmentRepository nacosEnvironmentRepository() { + return new NacosEnvironmentRepository(); + } + +} diff --git a/spring-cloud-alibaba-nacos-config-server/src/main/java/org/springframework/cloud/alibaba/nacos/config/server/environment/NacosEnvironmentRepository.java b/spring-cloud-alibaba-nacos-config-server/src/main/java/org/springframework/cloud/alibaba/nacos/config/server/environment/NacosEnvironmentRepository.java new file mode 100644 index 000000000..50b054aa1 --- /dev/null +++ b/spring-cloud-alibaba-nacos-config-server/src/main/java/org/springframework/cloud/alibaba/nacos/config/server/environment/NacosEnvironmentRepository.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cloud.alibaba.nacos.config.server.environment; + +import com.alibaba.nacos.config.server.model.ConfigInfo; +import com.alibaba.nacos.config.server.service.PersistService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.config.environment.Environment; +import org.springframework.cloud.config.environment.PropertySource; +import org.springframework.cloud.config.server.environment.EnvironmentRepository; +import org.springframework.util.StringUtils; + +import java.io.IOException; +import java.io.StringReader; +import java.util.Properties; + +import static com.alibaba.nacos.config.server.constant.Constants.DEFAULT_GROUP; + +/** + * Nacos {@link EnvironmentRepository} + * + * @author Mercy + * @since 0.2.0 + */ +public class NacosEnvironmentRepository implements EnvironmentRepository { + + @Autowired + private PersistService persistService; + + @Override + public Environment findOne(String application, String profile, String label) { + + String dataId = application + "-" + profile + ".properties"; + + ConfigInfo configInfo = persistService.findConfigInfo(dataId, DEFAULT_GROUP, label); + + return createEnvironment(configInfo, application, profile); + } + + private Environment createEnvironment(ConfigInfo configInfo, String application, String profile) { + + Environment environment = new Environment(application, profile); + + Properties properties = createProperties(configInfo); + + String propertySourceName = String.format("Nacos[application : %s , profile : %s]", application, profile); + + PropertySource propertySource = new PropertySource(propertySourceName, properties); + + environment.add(propertySource); + + return environment; + } + + private Properties createProperties(ConfigInfo configInfo) { + Properties properties = new Properties(); + String content = configInfo == null ? null : configInfo.getContent(); + if (StringUtils.hasText(content)) { + try { + properties.load(new StringReader(content)); + } catch (IOException e) { + throw new IllegalStateException("The format of content is a properties"); + } + } + return properties; + } + + private static String[] of(String... values) { + return values; + } +} diff --git a/spring-cloud-alibaba-nacos-config-server/src/main/resources/META-INF/spring.factories b/spring-cloud-alibaba-nacos-config-server/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..861f60f02 --- /dev/null +++ b/spring-cloud-alibaba-nacos-config-server/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Auto-Configuration +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.cloud.alibaba.nacos.config.server.NacosConfigServerAutoConfiguration \ No newline at end of file diff --git a/spring-cloud-alibaba-nacos-config-server/src/test/java/org/springframework/cloud/alibaba/nacos/config/server/bootstrap/NacosConfigServerBootstrap.java b/spring-cloud-alibaba-nacos-config-server/src/test/java/org/springframework/cloud/alibaba/nacos/config/server/bootstrap/NacosConfigServerBootstrap.java new file mode 100644 index 000000000..68d92e7db --- /dev/null +++ b/spring-cloud-alibaba-nacos-config-server/src/test/java/org/springframework/cloud/alibaba/nacos/config/server/bootstrap/NacosConfigServerBootstrap.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cloud.alibaba.nacos.config.server.bootstrap; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.cloud.config.server.EnableConfigServer; + +/** + * Nacos Config Server Bootstrap + * + * @author Mercy + * @since 0.2.0 + */ +@EnableAutoConfiguration +@EnableConfigServer +public class NacosConfigServerBootstrap { + + public static void main(String[] args) { + System.setProperty("nacos.standalone", "true"); + SpringApplication.run(NacosConfigServerBootstrap.class); + } +} diff --git a/spring-cloud-alibaba-nacos-config-server/src/test/resources/application.properties b/spring-cloud-alibaba-nacos-config-server/src/test/resources/application.properties new file mode 100644 index 000000000..dcecabe77 --- /dev/null +++ b/spring-cloud-alibaba-nacos-config-server/src/test/resources/application.properties @@ -0,0 +1,2 @@ +spring.application.name=nacos-config-server +management.endpoints.web.exposure.include=* \ No newline at end of file From 9fbe1aa3c502a5dc4461f5a44629b9ac66d4f86f Mon Sep 17 00:00:00 2001 From: xiaolongzuo <150349407@qq.com> Date: Thu, 8 Nov 2018 14:59:05 +0800 Subject: [PATCH 02/23] Add ANS and ACM readme doc. --- .../acm-local-example/readme-zh.md | 46 +++++++++++++++++ .../src/main/resources/bootstrap.properties | 1 - .../ans-consumer-feign-example/readme-zh.md | 25 ++++++++++ .../ans-consumer-ribbon-example/readme-zh.md | 25 ++++++++++ .../ans-provider-example/readme-zh.md | 35 +++++++++++++ .../oss-example/readme-zh.md | 48 ++++++------------ .../oss-example/readme.md | 50 ++++++------------- .../src/main/resources/oss-test.json | 2 +- 8 files changed, 162 insertions(+), 70 deletions(-) create mode 100644 spring-cloud-alibaba-examples/acm-example/acm-local-example/readme-zh.md create mode 100644 spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/readme-zh.md create mode 100644 spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/readme-zh.md create mode 100644 spring-cloud-alibaba-examples/ans-example/ans-provider-example/readme-zh.md diff --git a/spring-cloud-alibaba-examples/acm-example/acm-local-example/readme-zh.md b/spring-cloud-alibaba-examples/acm-example/acm-local-example/readme-zh.md new file mode 100644 index 000000000..f76577aa9 --- /dev/null +++ b/spring-cloud-alibaba-examples/acm-example/acm-local-example/readme-zh.md @@ -0,0 +1,46 @@ +# ACM Local Example + +## 项目说明 + +本项目展示了,在Spring Cloud规范下,如何以最简单且免费的方式,使用ACM产品,将配置统一管理。 + +应用配置管理(Application Configuration Management,简称 ACM),其前身为淘宝内部配置中心 Diamond,是一款应用配置中心产品。基于该应用配置中心产品,您可以在微服务、DevOps、大数据等场景下极大地减轻配置管理的工作量的同时,保证配置的安全合规。更多 ACM 相关的信息,请参考 [ACM官网](https://www.aliyun.com/product/acm)。 + +## 示例 + +### 准备工作 + +ACM支持直接使用免费的轻量版配置中心,进行开发和调试工作。本示例也是基于轻量版配置中心的,因此我们需要首先安装和启动轻量版配置中心。 + +1. [下载轻量版配置中心](https://edas-public.oss-cn-hangzhou.aliyuncs.com/install_package/LCC/2018-11-01/edas-lite-configcenter.tar.gz?file=edas-lite-configcenter.tar.gz) + +2. 解压 edas-lite-configcenter.tar.gz ,然后执行以下命令。 + + cd edas-config-center && sh startup.sh + +出现以下内容说明轻量版配置中心启动成功。 + + Edas-config-center has been started successfully. + You can see more details in logs/config-center.log. + +3. 进入页面 http://127.0.0.1:8080,在左侧"配置列表"页面中,点击"添加"按钮,添加如下配置。 + + Group:DEFAULT_GROUP + DataId:acm-local.properties + Content:user.id=xiaolongzuo + +### 启动应用 + +直接运行main class,即`AcmApplication`。 + +### 查看效果 + +1. 使用`curl`可以看到在配置中心配置的user.id。 + + curl http://127.0.0.1:18089/ + +2. 进入页面 http://127.0.0.1:8080,在左侧"配置列表"页面中,更改user.id的值以后,再次使用`curl`命令,可以看到配置变化。 + + +如果您对 Spring Cloud ACM Starter 有任何建议或想法,欢迎提交 issue 中或者通过其他社区渠道向我们反馈。 + diff --git a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties index 448a0c7dd..40947c21a 100644 --- a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties +++ b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties @@ -1,4 +1,3 @@ -spring.application.group=com.alibaba.acm spring.application.name=acm-local server.port=18089 spring.cloud.alicloud.acm.server-list=127.0.0.1 diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/readme-zh.md b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/readme-zh.md new file mode 100644 index 000000000..4b8ad3728 --- /dev/null +++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/readme-zh.md @@ -0,0 +1,25 @@ +# ANS Consumer Feign Example + +## 项目说明 + +本项目展示了,在Spring Cloud规范下,如何以最简单且免费的方式,使用Feign客户端,调用一个服务。 + +## 示例 + +### 准备工作 + +ans-provider-example已经成功启动,并发布服务成功。 + +### 启动应用 + +直接运行main class,即`ConsumerApplication`。 + +### 查看效果 + +使用`curl`命令可以看到应用打印出相应的调用日志,命令如下。 + + curl http://127.0.0.1:18082/ + + +如果您对 Spring Cloud ANS Starter 有任何建议或想法,欢迎提交 issue 中或者通过其他社区渠道向我们反馈。 + diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/readme-zh.md b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/readme-zh.md new file mode 100644 index 000000000..b15eb89c6 --- /dev/null +++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/readme-zh.md @@ -0,0 +1,25 @@ +# ANS Consumer Ribbon Example + +## 项目说明 + +本项目展示了,在Spring Cloud规范下,如何以最简单且免费的方式,使用Ribbon客户端,调用一个服务。 + +## 示例 + +### 准备工作 + +ans-provider-example已经成功启动,并发布服务成功。 + +### 启动应用 + +直接运行main class,即`ConsumerApplication`。 + +### 查看效果 + +使用`curl`命令可以看到应用打印出相应的调用日志,命令如下。 + + curl http://127.0.0.1:18082/ + + +如果您对 Spring Cloud ANS Starter 有任何建议或想法,欢迎提交 issue 中或者通过其他社区渠道向我们反馈。 + diff --git a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/readme-zh.md b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/readme-zh.md new file mode 100644 index 000000000..82b158740 --- /dev/null +++ b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/readme-zh.md @@ -0,0 +1,35 @@ +# ANS Provider Example + +## 项目说明 + +本项目展示了,在Spring Cloud规范下,如何以最简单且免费的方式,发布一个服务。 + +## 示例 + +### 准备工作 + +ANS支持直接使用免费的轻量版配置中心,进行开发和调试工作。本示例也是基于轻量版配置中心的,因此我们需要首先安装和启动轻量版配置中心。 + +1. [下载轻量版配置中心](https://edas-public.oss-cn-hangzhou.aliyuncs.com/install_package/LCC/2018-11-01/edas-lite-configcenter.tar.gz?file=edas-lite-configcenter.tar.gz) + +2. 解压 edas-lite-configcenter.tar.gz ,然后执行以下命令。 + + cd edas-config-center && sh startup.sh + +出现以下内容说明轻量版配置中心启动成功。 + + Edas-config-center has been started successfully. + You can see more details in logs/config-center.log. + + +### 启动应用 + +直接运行main class,即`ProviderApplication`。 + +### 查看效果 + +进入页面 http://127.0.0.1:8080,在左侧"服务列表"页面中,可以看到一条名为`ans-provider`的服务。 + + +如果您对 Spring Cloud ANS Starter 有任何建议或想法,欢迎提交 issue 中或者通过其他社区渠道向我们反馈。 + diff --git a/spring-cloud-alibaba-examples/oss-example/readme-zh.md b/spring-cloud-alibaba-examples/oss-example/readme-zh.md index 56ac5cb68..54cc88d28 100644 --- a/spring-cloud-alibaba-examples/oss-example/readme-zh.md +++ b/spring-cloud-alibaba-examples/oss-example/readme-zh.md @@ -11,7 +11,7 @@ ### 接入 OSS 在启动示例进行演示之前,我们先了解一下如何接入 OSS。 -**注意:本节只是为了便于您理解接入方式,本示例代码中已经完成接入工作,您只需修改 accessKeyId、secretAccessKey、region 即可。** +**注意:本节只是为了便于您理解接入方式,本示例代码中已经完成接入工作,您只需修改 accessKey、secretKey、endpoint 即可。** 1. 修改 pom.xml 文件,引入 alicloud-oss starter。 @@ -20,24 +20,24 @@ spring-cloud-starter-alicloud-oss -2. 在配置文件中配置 OSS 服务对应的 accessKeyId、secretAccessKey 和 region。 +2. 在配置文件中配置 OSS 服务对应的 accessKey、secretKey 和 endpoint。 // application.properties - spring.cloud.alibaba.oss.accessKeyId=your-ak - spring.cloud.alibaba.oss.secretAccessKey=your-sk - spring.cloud.alibaba.oss.region=cn-beijing + spring.cloud.alicloud.access-key=your-ak + spring.cloud.alicloud.secret-key=your-sk + spring.cloud.alicloud.oss.endpoint=*** - 以阿里云 accessKeyId、secretAccessKey 为例,获取方式如下。 + 以阿里云 accessKey、secretKey 为例,获取方式如下。 i. 在阿里云控制台界面,单击右上角头像,选择 accesskeys,或者直接登录[用户信息管理界面](https://usercenter.console.aliyun.com/): ![undefined](https://cdn.nlark.com/lark/0/2018/png/64647/1535371973274-3ebec90a-ebde-4eb7-96ed-5372f6b32fe0.png) - ii. 获取 accessKeyId、secretAccessKey: + ii. 获取 accessKey、secretKey: ![undefined](https://cdn.nlark.com/lark/0/2018/png/64647/1535372168883-b94a3d77-3f81-4938-b409-611945a9e21c.png) - **注意:**如果您使用了阿里云 [STS服务](https://help.aliyun.com/document_detail/28756.html) 进行短期访问权限管理,则除了 accessKeyId、secretAccessKey、region 以外,还需配置 securityToken。 + **注意:**如果您使用了阿里云 [STS服务](https://help.aliyun.com/document_detail/28756.html) 进行短期访问权限管理,则除了 accessKey、secretKey、endpoint 以外,还需配置 securityToken。 3. 注入 OSSClient 并进行文件上传下载等操作。 @@ -61,9 +61,9 @@ spring.application.name=oss-example server.port=18084 - spring.cloud.alibaba.oss.accessKeyId=your-ak - spring.cloud.alibaba.oss.secretAccessKey=your-sk - spring.cloud.alibaba.oss.region=cn-beijing + spring.cloud.alicloud.access-key=your-ak + spring.cloud.alicloud.secret-key=your-sk + spring.cloud.alicloud.oss.endpoint=*** 2. 通过 IDE 直接启动或者编译打包后启动应用。 @@ -72,7 +72,7 @@ 1. 执行 `mvn clean package` 将工程编译打包; 2. 执行 `java -jar oss-example.jar`启动应用。 -应用启动后会自动在 OSS 上创建一个名为 `spring-cloud-alibaba` 的 Bucket。 +应用启动后会自动在 OSS 上创建一个名为 `spring-cloud-alibaba-test` 的 Bucket。 ### 上传或下载文件 @@ -96,7 +96,7 @@ 显示结果: // 如果配置正确,则输出 - download success, content: { "name": "spring-cloud-alibaba", "github": "https://github.com/spring-cloud-incubator/spring-cloud-alibaba", "authors": ["Jim", "flystar32"], "emails": ["fangjian0423@gmail.com", "flystar32@163.com"] } + download success, content: { "name": "oss-test" } // 下载的过程中如果发生异常,则会输出download fail: fail reason。比如accessKeyId配置错误,则fail reason内容如下 download fail: The OSS Access Key Id you provided does not exist in our records. [ErrorCode]: InvalidAccessKeyId [RequestId]: RequestId [HostId]: xxx.oss-cn-beijing.aliyuncs.com [ResponseError]: InvalidAccessKeyId The OSS Access Key Id you provided does not exist in our records. RequestId sxxx.oss-cn-beijing.aliyuncs.com xxx-accessKeyId @@ -106,11 +106,11 @@ 完成文件上传或者下载操作后,可以登录 OSS 控制台进行验证。 -1. 登陆[OSS控制台](https://oss.console.aliyun.com/),可以看到左侧 Bucket 列表新增一个名字为`spring-cloud-alibaba`的 Bucket。 +1. 登陆[OSS控制台](https://oss.console.aliyun.com/),可以看到左侧 Bucket 列表新增一个名字为`spring-cloud-alibaba-test`的 Bucket。 ![undefined](https://cdn.nlark.com/lark/0/2018/png/64647/1535369224513-387afdf9-6078-4a42-9f18-d9fe9926a9cd.png) -2. 单击`spring-cloud-alibaba` Bucket,选择 `文件管理` 页签,发现上传的 oss-test 文件在 custom-dir 目录中。上传的 objectName 为`custom-dir/oss-test`。目录和文件以'/'符号分割。 +2. 单击`spring-cloud-alibaba-test` Bucket,选择 `文件管理` 页签,发现上传的 oss-test 文件。上传的 objectName 为`oss-test.json`。目录和文件以'/'符号分割。 ![undefined](https://cdn.nlark.com/lark/0/2018/png/64647/1535615378605-df1381e9-c5ff-4da1-b3b3-ce9acfef313f.png) @@ -134,24 +134,6 @@ Endpoint 内部会显示所有的 OSSClient 配置信息,以及该 OSSClient ![undefined](https://cdn.nlark.com/lark/0/2018/png/64647/1535373658171-20674565-6fe1-4e1e-a596-1dd6f4159ec3.png) - -## 多个 OSSClient 场景 - -如果您需要配置多个 OSSClient,类似多数据源的配置,则可以先构造 `OSSProperties`,再构造 `OSSClient`,并分别为每个 OSSClient 配置相应的 accessKeyId、secretAccessKey 等信息。 - - @Bean - @ConfigurationProperties(prefix = "spring.cloud.alibaba.oss1") - public OSSProperties ossProperties1() { - return new OSSProperties(); - } - - @Bean - public OSS ossClient1(@Qualifier("ossProperties1") OSSProperties ossProperties) { - return new OSSClientBuilder().build(ossProperties.getEndpoint(), - ossProperties.getAccessKeyId(), ossProperties.getSecretAccessKey(), - ossProperties.getSecurityToken(), ossProperties.getConfiguration()); - } -

以 Resource 的形式读取文件

OSS Starter 支持以 Resource 的形式得到文件对象。如果只需读取少量文件,您可以使用这种方式。 diff --git a/spring-cloud-alibaba-examples/oss-example/readme.md b/spring-cloud-alibaba-examples/oss-example/readme.md index 17dfbbdc3..11ea77c82 100644 --- a/spring-cloud-alibaba-examples/oss-example/readme.md +++ b/spring-cloud-alibaba-examples/oss-example/readme.md @@ -11,7 +11,7 @@ If your applications are Spring Cloud applications and you need to use Alibaba C ### Connect to OSS Before we start the demo, let's learn how to connect OSS to a Spring Cloud application. -**Note: This section is to show you how to connect to oss. The actual configurations have been completed in the following example, and you only need to specify your accessKeyId, secretAccessKey and region.** +**Note: This section is to show you how to connect to oss. The actual configurations have been completed in the following example, and you only need to specify your accessKey, secretKey and endpoint.** 1. Add dependency spring-cloud-starter-alicloud-oss in the pom.xml file in your Spring Cloud project. @@ -23,21 +23,21 @@ Before we start the demo, let's learn how to connect OSS to a Spring Cloud appli 2. Configure accessKeyId, secretAccessKey and region in application.properties. // application.properties - spring.cloud.alibaba.oss.accessKeyId=your-ak - spring.cloud.alibaba.oss.secretAccessKey=your-sk - spring.cloud.alibaba.oss.region=cn-beijing + spring.cloud.alicloud.access-key=your-ak + spring.cloud.alicloud.secret-key=your-sk + spring.cloud.alicloud.oss.endpoint=*** - To get accessKeyId, secretAccessKey, follow these steps: + To get accessKey, secretKey, follow these steps: 1. On the Alibaba Cloud console, click your avatar on the upper-right corner and click accesskeys. Or visit [User Management](https://usercenter.console.aliyun.com/) page directly: ![undefined](https://cdn.nlark.com/lark/0/2018/png/64647/1535464041257-5c7ae997-daff-45b3-89d4-02d578da4ac7.png) - 2. Get your accessKeyId、secretAccessKey: + 2. Get your accessKey、secretKey: ![undefined](https://cdn.nlark.com/lark/0/2018/png/64647/1535464098793-517491f6-156b-4a98-a5a4-6113cb3c01a4.png) - **Note:** If you are using [STS](https://www.alibabacloud.com/help/doc-detail/28756.html), you should configure securityToken in addition to accessKeyId, secretAccessKey, and region. + **Note:** If you are using [STS](https://www.alibabacloud.com/help/doc-detail/28756.html), you should configure securityToken in addition to accessKey, secretKey, and endpoint. 3. Inject OSSClient and use it to upload files to the OSS server and download a file from OSS server. @@ -60,9 +60,9 @@ Before we start the demo, let's learn how to connect OSS to a Spring Cloud appli spring.application.name=oss-example server.port=18084 - spring.cloud.alibaba.oss.accessKeyId=your-ak - spring.cloud.alibaba.oss.secretAccessKey=your-sk - spring.cloud.alibaba.oss.region=cn-beijing + spring.cloud.alicloud.access-key=your-ak + spring.cloud.alicloud.secret-key=your-sk + spring.cloud.alicloud.oss.endpoint=*** 2. Start the application in IDE or by building a fatjar. @@ -71,7 +71,7 @@ Before we start the demo, let's learn how to connect OSS to a Spring Cloud appli 1. Execute command `mvn clean package` to build a fatjar. 2. Run command `java -jar oss-example.jar` to start the application. -After startup, a bucket called 'spring-cloud-alibaba' is automatically created in OSS. +After startup, a bucket called 'spring-cloud-alibaba-test' is automatically created in OSS. ### Upload or download files @@ -88,14 +88,14 @@ Results: upload fail: The OSS Access Key Id you provided does not exist in our records. [ErrorCode]: InvalidAccessKeyId [RequestId]: RequestId [HostId]: xxx.oss-cn-beijing.aliyuncs.com [ResponseError]: InvalidAccessKeyId The OSS Access Key Id you provided does not exist in our records. RequestId xxx.oss-cn-beijing.aliyuncs.com xxx-accessKeyId #### Download files -Use `curl` command to download files. It will download the oss-test.json file that you uploaded just now and print in result): +Use `curl` command to download files. It will download the oss-test.json file that you uploaded just now and print in result: curl http://localhost:18084/download Results: // If configurations are correct, the output will be as follows - download success, content: { "name": "spring-cloud-alibaba", "github": "https://github.com/spring-cloud-incubator/spring-cloud-alibaba", "authors": ["Jim", "flystar32"], "emails": ["fangjian0423@gmail.com", "flystar32@163.com"] } + download success, content: { "name": "oss-tes" } // If an error occurs during downloading, the output will be 'download fail: fail reason'. For example, if accessKeyId is wrong,fail reason will be as follows download fail: The OSS Access Key Id you provided does not exist in our records. [ErrorCode]: InvalidAccessKeyId [RequestId]: RequestId [HostId]: xxx.oss-cn-beijing.aliyuncs.com [ResponseError]: InvalidAccessKeyId The OSS Access Key Id you provided does not exist in our records. RequestId sxxx.oss-cn-beijing.aliyuncs.com xxx-accessKeyId @@ -103,11 +103,11 @@ Results: ### Verify results on OSS You can verify results on the OSS console when you finish uploading or downloading files. -1. Log on to the [OSS console](https://oss.console.aliyun.com/),and you will find a bucket named `spring-cloud-alibaba`. +1. Log on to the [OSS console](https://oss.console.aliyun.com/),and you will find a bucket named `spring-cloud-alibaba-test`. ![undefined](https://cdn.nlark.com/lark/0/2018/png/64647/1535464204462-ccebb9e0-7233-499c-8dec-8b8348231b2b.png) -2. Click the `spring-cloud-alibaba` bucket, select the Files tab, and you will find the oss-test file. The file 'oss-test' is located in directory 'custom-dir'. The objectName of the file is 'custom-dir/oss-test'. File directory and file is separated by '/'. +2. Click the `spring-cloud-alibaba-test` bucket, select the Files tab, and you will find the oss-test.json file. The objectName of the file is 'oss-test.json'. File directory and file is separated by '/'. ![undefined](https://cdn.nlark.com/lark/0/2018/png/64647/1535618026281-613a338c-f89c-4c7b-8b04-d404d1320699.png) @@ -133,26 +133,6 @@ Endpoint will show the configurations and the list of buckets of all OSSClients. ![undefined](https://cdn.nlark.com/lark/0/2018/png/64647/1535373658171-20674565-6fe1-4e1e-a596-1dd6f4159ec3.png) -## Multiple OSSClients - -If you need multiple OSSClients,like Multi DataSources, build `OSSProperties` first,and then build `OSSClient`. Specify information such as assessKeyId and secrectAccessKey for each OSSClient. - - @Bean - @ConfigurationProperties(prefix = "spring.cloud.alibaba.oss1") - public OSSProperties ossProperties1() { - return new OSSProperties(); - } - - @Bean - public OSS ossClient1(@Qualifier("ossProperties1") OSSProperties ossProperties) { - return new OSSClientBuilder().build(ossProperties.getEndpoint(), - ossProperties.getAccessKeyId(), ossProperties.getSecretAccessKey(), - ossProperties.getSecurityToken(), ossProperties.getConfiguration()); - } - - -* OSSClient shutdown:You do not need to shutdown OSSClient. It will be done in `OSSApplicationListener`. -

Read file using resource mode

OSS Starter supports getting file objects by `Spring Resource`. Simply configure OSS protocol of the resource: diff --git a/spring-cloud-alibaba-examples/oss-example/src/main/resources/oss-test.json b/spring-cloud-alibaba-examples/oss-example/src/main/resources/oss-test.json index f1683e94f..68682f46e 100644 --- a/spring-cloud-alibaba-examples/oss-example/src/main/resources/oss-test.json +++ b/spring-cloud-alibaba-examples/oss-example/src/main/resources/oss-test.json @@ -1,3 +1,3 @@ { - "name": "chenzhu-test" + "name": "oss-test" } \ No newline at end of file From 5ab8c2385f547c445b8638ffe783d895b5083717 Mon Sep 17 00:00:00 2001 From: xiaolongzuo <150349407@qq.com> Date: Thu, 8 Nov 2018 15:03:28 +0800 Subject: [PATCH 03/23] Add ANS and ACM readme doc. --- README-zh.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README-zh.md b/README-zh.md index 06732dba4..d30367c85 100644 --- a/README-zh.md +++ b/README-zh.md @@ -1,6 +1,6 @@ # Spring Cloud Alibaba -Spring Cloud Alibaba 致力于提供分布式应用服务开发的一站式解决方案。此项目包含开发分布式应用服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发分布式应用服务。 +Spring Cloud Alibaba 致力于提供基于微服务架构开发分布式应用的一站式解决方案。此项目包含开发分布式应用服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发分布式应用服务。 依托 Spring Cloud Alibaba,您只需要添加一些注解和少量配置,就可以将 Spring Cloud 应用接入阿里分布式应用解决方案,通过阿里中间件来迅速搭建分布式应用系统。 @@ -94,6 +94,10 @@ Example 列表: [AliCloud OSS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/oss-example/readme-zh.md) +[AliCloud ANS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/ans-example/ans-provider-example/readme-zh.md) + +[AliCloud ACM Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/acm-example/acm-local-example/readme-zh.md) + ## 版本管理规范 项目的版本号格式为 x.x.x 的形式,其中 x 的数值类型为数字,从0开始取值,且不限于 0~9 这个范围。项目处于孵化器阶段时,第一位版本号固定使用0,即版本号为 0.x.x 的格式。 From 49ca7c6885ba713f75e282acc6552a904ed8eafc Mon Sep 17 00:00:00 2001 From: xiaojing Date: Thu, 8 Nov 2018 15:28:58 +0800 Subject: [PATCH 04/23] update readme --- README-zh.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README-zh.md b/README-zh.md index d30367c85..dd151cf63 100644 --- a/README-zh.md +++ b/README-zh.md @@ -1,13 +1,13 @@ # Spring Cloud Alibaba -Spring Cloud Alibaba 致力于提供基于微服务架构开发分布式应用的一站式解决方案。此项目包含开发分布式应用服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发分布式应用服务。 +Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案。此项目包含开发分布式应用微服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发分布式应用服务。 -依托 Spring Cloud Alibaba,您只需要添加一些注解和少量配置,就可以将 Spring Cloud 应用接入阿里分布式应用解决方案,通过阿里中间件来迅速搭建分布式应用系统。 +依托 Spring Cloud Alibaba,您只需要添加一些注解和少量配置,就可以将 Spring Cloud 应用接入阿里微服务解决方案,通过阿里中间件来迅速搭建分布式应用系统。 ## 主要功能 -* **服务限流降级**:默认支持为 HTTP 服务的提供限流保护,也支持添加注解实现方法的自定义限流降级,且支持动态修改限流降级规则。 +* **服务限流降级**:默认支持 Servlet、RestTemplate、Dubbo 和 RocketMQ 限流降级功能的接入,可以在运行时通过控制台实时修改限流降级规则,还支持查看限流降级 Metrics 监控。 * **服务注册与发现**:适配 Spring Cloud 服务注册与发现标准,默认集成了 Ribbon 的支持。 * **分布式配置管理**:支持分布式系统中的外部化配置,配置更改时自动刷新。 * **阿里云对象存储**:阿里云提供的海量、安全、低成本、高可靠的云存储服务。支持在任何应用、任何时间、任何地点存储和访问任意类型的数据。 From 9450826f47c41a217253580ff895e24e674cec14 Mon Sep 17 00:00:00 2001 From: flystar32 Date: Thu, 8 Nov 2018 19:07:17 +0800 Subject: [PATCH 05/23] fix typo --- README-zh.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README-zh.md b/README-zh.md index dd151cf63..3c26ba94d 100644 --- a/README-zh.md +++ b/README-zh.md @@ -48,7 +48,7 @@ Spring Cloud 使用 Maven 来构建,最快的使用方式是将本项目clone org.springframework.cloud spring-cloud-alibaba-dependencies - 0.2.0.REALEASE + 0.2.0.RELEASE pom import diff --git a/README.md b/README.md index c70bd1f18..e45c7e2d1 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ These artifacts are available from Maven Central and Spring Release repository v org.springframework.cloud spring-cloud-alibaba-dependencies - 0.2.0.REALEASE + 0.2.0.RELEASE pom import From 80368052af2be87ffb9826572d639c32363b8f69 Mon Sep 17 00:00:00 2001 From: xiaolongzuo <150349407@qq.com> Date: Thu, 8 Nov 2018 19:28:33 +0800 Subject: [PATCH 06/23] Update ref doc. --- .../src/main/asciidoc-zh/spring-cloud-alibaba.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/spring-cloud-alibaba.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/spring-cloud-alibaba.adoc index 6a05ccde7..77083a323 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/spring-cloud-alibaba.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/spring-cloud-alibaba.adoc @@ -9,7 +9,7 @@ xiaojing; xiaolongzuo; jim fang; bingting peng == 介绍 -Spring Cloud Alibaba 致力于提供分布式应用服务开发的一站式解决方案。此项目包含开发分布式应用服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发分布式应用服务。 +Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案。此项目包含开发分布式应用服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发分布式应用服务。 依托 Spring Cloud Alibaba,您只需要添加一些注解和少量配置,就可以将 Spring Cloud 应用接入阿里分布式应用解决方案,通过阿里中间件来迅速搭建分布式应用系统。 From 88a870dc5de692277ae8e4a0fea82272419a81f6 Mon Sep 17 00:00:00 2001 From: pengbingting Date: Tue, 13 Nov 2018 09:51:36 +0800 Subject: [PATCH 07/23] =?UTF-8?q?=E6=9B=B4=E6=94=B9Nacos=E7=9A=84=E6=8B=BC?= =?UTF-8?q?=E5=86=99=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/asciidoc-zh/nacos-config.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc index be46404b7..b3f9fb5bd 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc @@ -6,7 +6,7 @@ ==== Nacos 服务端初始化 -1、启动Nacos Server。启动方式可见 https://nacos.io/zh-cn/docs/quick-start.html[Naocs 官网] +1、启动Nacos Server。启动方式可见 https://nacos.io/zh-cn/docs/quick-start.html[Nacos 官网] 2、启动好Nacos之后,在Nacos添加如下的配置。注意data id是以 properties为扩展名,默认的文件扩展名方式。如下所示: From daa398dd3281d6467ac2ea2d158bb79dedaad79c Mon Sep 17 00:00:00 2001 From: xiaolongzuo <150349407@qq.com> Date: Tue, 13 Nov 2018 17:47:04 +0800 Subject: [PATCH 08/23] Update ref doc. --- .../src/main/asciidoc-zh/acm.adoc | 2 +- .../src/main/asciidoc-zh/ans.adoc | 110 ++++++++++++ .../src/main/asciidoc-zh/oss.adoc | 156 ++++++++++++++++++ 3 files changed, 267 insertions(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/acm.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/acm.adoc index 143e764a5..16ff206c0 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/acm.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/acm.adoc @@ -1,6 +1,6 @@ = Spring Cloud AliCloud ACM -Spring Cloud Alibaba Config 提供了和阿里云上的ACM的集成。使得在项目中如果需要上云的用户可以非常方便无缝的对接阿里云,来享受云端提供的稳定服务。 +Spring Cloud AliCloud ACM 提供了和阿里云上的ACM的集成。使得在项目中如果需要上云的用户可以非常方便无缝的对接阿里云,来享受云端提供的稳定服务。 === 快速开始 diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/ans.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/ans.adoc index b9b34ce24..63c839763 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/ans.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/ans.adoc @@ -1 +1,111 @@ == Spring Cloud AliCloud ANS + +ANS(Application Naming Service) 是隶属于阿里云EDAS产品的组件, Spring Cloud AliCloud ANS 提供了Spring Cloud规范下商业版的服务注册与发现,可以让用户方便的在本地开发,同时也可以运行在云环境里。 + +=== 如何引入 Spring Cloud AliCloud ANS + +Spring Cloud Alibaba 已经发布了0.2.0版本,需要首先导入依赖管理POM。 + +[source,xml] +---- + + + + org.springframework.cloud + spring-cloud-alibaba-dependencies + 0.2.0.RELEASE + pom + import + + + +---- + +接下来引入 Spring Cloud AliCloud ANS Starter 即可。 + +[source,xml] +---- + + org.springframework.cloud + spring-cloud-starter-alicloud-ans + +---- + +=== 使用ANS进行服务注册 + +当客户端引入了 Spring Cloud AliCloud ANS Starter 以后,服务的元数据会被自动注册到注册中心,比如IP、端口、权重等信息。客户端会与服务端保持心跳,来证明自己可以正常提供服务。 + +以下是一个简单的应用示例。 + +[source,java] +---- +@SpringBootApplication +@EnableDiscoveryClient +@RestController +public class ProviderApplication { + + @RequestMapping("/") + public String home() { + return "Hello world"; + } + + public static void main(String[] args) { + SpringApplication.run(ProviderApplication.class, args); + } + +} +---- + +既然服务会被注册到注册中心,那么肯定需要配置注册中心的地址,在application.properties中,还需要配置上以下地址。 + +[source,properties] +---- +# 应用名会被作为服务名称使用,因此会必选 +spring.application.name=ans-provider +server.port=18081 +# 以下就是注册中心的IP和端口配置,因为默认就是127.0.0.1和8080,因此以下两行配置也可以省略 +spring.cloud.alicloud.ans.server.list=127.0.0.1 +spring.cloud.alicloud.ans.server.port=8080 +---- + +NOTE: 此时没有启动注册中心,启动应用会报错,因此在应用启动之前,应当首先启动注册中心。 + +=== 启动注册中心 + +ANS使用的注册中心有两种,一种是完全免费的轻量版配置中心,主要用于开发和本地调试,一种是云上注册中心,ANS依托于阿里云EDAS产品提供服务注册的功能。通常情况下,可以使用轻量版配置中心作为开发和测试环境,使用云上的EDAS作为灰度和生产环境。 + +==== 启动轻量版配置中心 + +轻量版配置中心的下载和启动方式可参考 https://help.aliyun.com/document_detail/44163.html?spm=a2c4g.11186623.6.677.5f206b82Z2mTCF[这里] + +NOTE: 只需要进行第1步(下载轻量配置中心)和第2步(启动轻量配置中心)即可,第3步(配置hosts)在与 ANS 结合使用时,不需要操作。 + +启动完轻量版配置中心以后,直接启动 ProviderApplication ,即可将服务注册到轻量版配置中心,由于轻量版配置中心的默认端口是8080,因此你可以打开 http://127.0.0.1:8080 ,点击左侧"服务列表",查看注册上来的服务。 + +==== 使用云上注册中心 + +使用云上注册中心,可以省去服务端的维护工作,同时稳定性也会更有保障。当使用云上注册中心时,代码部分和使用轻量配置中心并没有区别,但是配置上会有一些区别。 + +以下是一个简单的使用云上配置中心的配置示例。 + +[source,properties] +---- +# 应用名会被作为服务名称使用,因此是必选 +spring.application.name=ans-provider +# 端口配置自由配置即可 +server.port=18081 +# 以下就是注册中心的IP和端口配置,因为默认就是127.0.0.1和8080,因此以下两行配置也可以省略 +spring.cloud.alicloud.ans.server-mode=EDAS +spring.cloud.alicloud.access-key=你的阿里云AK +spring.cloud.alicloud.secret-key=你的阿里云SK +spring.cloud.alicloud.edas.namespace=cn-xxxxx +---- + +server-mode 的默认值为 LOCAL ,如果要使用云上注册中心,则需要更改为 EDAS 。 + +access-key 和 secret-key 则是阿里云账号的AK/SK,需要首先注册阿里云账号,然后登陆 https://usercenter.console.aliyun.com/#/manage/ak[阿里云AK/SK管理页面] ,即可看到 AccessKey ID 和 Access Key Secret ,如果没有的话,需要点击"创建AccessKey"按钮创建。 + +namespace 是阿里云EDAS产品的概念,用于隔离不同的环境,比如测试环境和生产环境。要获取 namespace 需要 https://common-buy.aliyun.com/?spm=5176.11451019.0.0.6f5965c0Uq5tue&commodityCode=edaspostpay#/buy[开通EDAS服务],按量计费模式下开通是免费的,开通以后进入 https://edas.console.aliyun.com/#/namespaces?regionNo=cn-hangzhou[EDAS控制台],即可看到对应的namespace,比如cn-hangzhou。 + +NOTE: EDAS提供应用托管服务,如果你将应用托管到EDAS,那么EDAS将会自动为你填充所有配置。 + diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/oss.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/oss.adoc index 20b43f75f..778a8560c 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/oss.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/oss.adoc @@ -1 +1,157 @@ == Spring Cloud AliCloud OSS + +OSS(Object Storage Service)是阿里云的一款对象存储服务产品, Spring Cloud AliCloud OSS 提供了Spring Cloud规范下商业版的对象存储服务,提供简单易用的API,并且支持与 Spring 框架中 Resource 的整合。 + +=== 如何引入 Spring Cloud AliCloud OSS + +Spring Cloud Alibaba 已经发布了0.2.0版本,需要首先导入依赖管理POM。 + +[source,xml] +---- + + + + org.springframework.cloud + spring-cloud-alibaba-dependencies + 0.2.0.RELEASE + pom + import + + + +---- + +接下来引入 Spring Cloud AliCloud OSS Starter 即可。 + +[source,xml] +---- + + org.springframework.cloud + spring-cloud-starter-alicloud-oss + +---- + +=== 如何使用 OSS API + +==== 配置 OSS + +使用 Spring Cloud AliCloud OSS 之前,需要在 application.properties 中加入以下配置。 + +[source,properties] +---- +spring.cloud.alicloud.access-key=你的阿里云AK +spring.cloud.alicloud.secret-key=你的阿里云SK +spring.cloud.alicloud.oss.endpoint=***.aliyuncs.com +---- + +access-key 和 secret-key 是阿里云账号的AK/SK,需要首先注册阿里云账号,然后登陆 https://usercenter.console.aliyun.com/#/manage/ak[阿里云AK/SK管理页面] ,即可看到 AccessKey ID 和 Access Key Secret ,如果没有的话,需要点击"创建AccessKey"按钮创建。 + +endpoint可以到 OSS 的 https://help.aliyun.com/document_detail/31837.html?spm=a2c4g.11186623.2.9.7dc72841Z2hGqa#concept-zt4-cvy-5db[官方文档]中查看,根据所在的 region ,填写对应的 endpoint 即可。 + + +==== 引入 OSS API + +Spring Cloud Alicloud OSS 中的 OSS API 基于阿里云官方OSS SDK提供,具备上传、下载、查看等所有对象存储类操作API。 + +一个简单的使用 OSS API 的应用如下。 + +[source,java] +---- +@SpringBootApplication +public class OssApplication { + + @Autowired + private OSS ossClient; + + @RequestMapping("/") + public String home() { + ossClient.putObject("bucketName", "fileName", new FileInputStream("/your/local/file/path")); + return "upload success"; + } + + public static void main(String[] args) throws URISyntaxException { + SpringApplication.run(OssApplication.class, args); + } + +} +---- + +在上传文件之前,首先需要 https://account.aliyun.com/register/register.htm?spm=5176.8142029.388261.26.e9396d3eaYK2sG&oauth_callback=https%3A%2F%2Fwww.aliyun.com%2F[注册阿里云账号] ,如果已经有的话,请 https://common-buy.aliyun.com/?spm=5176.8465980.unusable.dopen.4cdf1450rg8Ujb&commodityCode=oss#/open[开通OSS服务]。 + +进入 https://oss.console.aliyun.com/overview[OSS控制台],点击左侧"新建Bucket",按照提示创建一个Bucket,然后将bucket名称替换掉上面代码中的"bucketName",而"fileName"取任意文件名,"/your/local/file/path"取任意本地文件路径,然后 curl http://127.0.0.1:端口/ 即可上传文件,可以到 https://oss.console.aliyun.com/overview[OSS控制台]查看效果。 + +更多关于 OSS API 的操作,可以参考 https://help.aliyun.com/document_detail/32008.html[OSS官方SDK文档]。 + +=== 与 Spring 框架的 Resource 结合 + +Spring Cloud AliCloud OSS 整合了 Spring 框架的 Resource 规范,可以让用户很方便的引用 OSS 的资源。 + +一个简单的使用 Resource 的例子如下。 + +[source,java] +---- +@SpringBootApplication +public class OssApplication { + + @Value("oss://bucketName/fileName") + private Resource file; + + @GetMapping("/file") + public String fileResource() { + try { + return "get file resource success. content: " + StreamUtils.copyToString( + file.getInputStream(), Charset.forName(CharEncoding.UTF_8)); + } catch (Exception e) { + return "get resource fail: " + e.getMessage(); + } + } + + public static void main(String[] args) throws URISyntaxException { + SpringApplication.run(OssApplication.class, args); + } + +} +---- + +NOTE: 以上示例运行的前提是,在 OSS 上需要有名为"bucketName"的Bucket,同时在该Bucket下,存在名为"fileName"的文件。 + +=== 采用 STS 授权 + +Spring Cloud AliCloud OSS 除了 AccessKey/SecretKey 的授权方式以外,还支持 STS 授权方式。 STS 是临时访问令牌的方式,一般用于授权第三方,临时访问自己的资源。 + +作为第三方,也就是被授权者,只需要配置以下内容,就可以访问临时被授权的资源。 + +[source,properties] +---- +spring.cloud.alicloud.oss.authorization-mode=STS +spring.cloud.alicloud.oss.endpoint=***.aliyuncs.com +spring.cloud.alicloud.oss.sts.access-key=你被授权的AK +spring.cloud.alicloud.oss.sts.secret-key=你被授权的SK +spring.cloud.alicloud.oss.sts.security-token=你被授权的ST +---- + +其中 spring.cloud.alicloud.oss.authorization-mode 是枚举类型,此时填写 STS ,代表采用 STS 的方式授权。 endpoint可以到 OSS 的 https://help.aliyun.com/document_detail/31837.html?spm=a2c4g.11186623.2.9.7dc72841Z2hGqa#concept-zt4-cvy-5db[官方文档]中查看,根据所在的 region ,填写对应的 endpoint 即可。 + +access-key、secret-key和security-token需要由授权方颁发,如果对 STS 不了解的话,可以参考 https://help.aliyun.com/document_detail/31867.html[STS官方文档]。 + +=== 更多客户端配置 + +除了基本的配置项以外, Spring Cloud AliCloud OSS 还支持很多额外的配置,也是在 application.properties 文件中。 + +以下是一些简单的示例。 + +[source,properties] +---- +spring.cloud.alicloud.oss.authorization-mode=STS +spring.cloud.alicloud.oss.endpoint=***.aliyuncs.com +spring.cloud.alicloud.oss.sts.access-key=你被授权的AK +spring.cloud.alicloud.oss.sts.secret-key=你被授权的SK +spring.cloud.alicloud.oss.sts.security-token=你被授权的ST + +spring.cloud.alicloud.oss.config.connection-timeout=3000 +spring.cloud.alicloud.oss.config.max-connections=1000 +---- + +如果想了解更多的配置项,可以参考 https://help.aliyun.com/document_detail/32010.html?spm=a2c4g.11186623.6.703.50b25413nGsYHc[OSSClient配置项] 的末尾表格。 + +NOTE: 通常情况下,都需要将 https://help.aliyun.com/document_detail/32010.html?spm=a2c4g.11186623.6.703.50b25413nGsYHc[OSSClient配置项] 末尾表格中的参数名更换成"-"连接,且所有字母小写。例如 ConnectionTimeout,对应 connection-timeout。 \ No newline at end of file From 3b0cc579a84eed21d220f16039eda33bbcc644da Mon Sep 17 00:00:00 2001 From: pengbingting Date: Wed, 14 Nov 2018 17:38:36 +0800 Subject: [PATCH 09/23] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Nacos=20Discovery=20?= =?UTF-8?q?=E7=9A=84reference=20=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/asciidoc-zh/nacos-discovery.adoc | 320 +++++++++++++++++- 1 file changed, 319 insertions(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc index 21a1177bf..d4a9a4c63 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc @@ -1 +1,319 @@ -== Spring Cloud Alibaba Nacos Discovery += Spring Cloud Alibaba Nacos Discovery + +该项目通过自动配置以及其他 Spring 编程模型的习惯用法为Spring Boot 应用程序在服务注册与发现方面提供和Nacos的无缝集成。 +通过一些简单的注解,您可以快速来注册一个服务,并使用经过双十一考验的Nacos组件来作为大规模分布式系统的服务注册中心。 + +== 1. 服务注册发现: Nacos Discovery Starter + +服务发现是微服务架构体系中最关键的组件之一。如果尝试着用手动的方式来给每一个客户端来配置所有服务提供者的服务列表是一件非常困难的事,而且也不利于 +服务的动态扩缩容。Nacos Discovery Starter 可以帮助您将服务自动注册到 Nacos 服务端并且能够动态感知和刷新某个服务实例的服务列表。除此之外,Nacos +Discovery Starter 也将服务实例自身的一些元数据信息-例如 host,port,健康检查URL,主页等-注册到 Nacos 。Nacos 的获取和启动方式可以参考 https://nacos.io/zh-cn/docs/quick-start.html[Nacos 官网]。 + +=== 如何引入 Nacos Discovery Starter + +为了能够在你的工程下引入 Nacos Discovey Starter,使用group ID 为 `org.springframework.cloud` 和 artifact ID 为 `spring-cloud-starter-alibaba-nacos-discovery`。 +pom.xml 示例如下所示: + +[source,xml,indent=0] +---- + + + + + org.springframework.cloud + spring-cloud-alibaba-dependencies + 0.2.0.RELEASE + pom + import + + + + + + + + org.springframework.cloud + spring-cloud-starter-alibaba-nacos-discovery + + +---- + +=== 启动一个 Provider 应用 + +如果您使用的 Spring Cloud 版本是 Finchley.SR1 版本,那么这个时候您的Spring Boot版本的选择可需要额外的小心了,因为版本的不匹对,可能会导致许多意外的效果。 +Spring Cloud 的 Finchley.SR1 版本最佳实践的 Spring Boot 版本是 2.0.6.RELEASE。在启动您的一个 Provider 应用时请检查依赖的 Spring Boot 版本是否是 +1.X.Y.RELEASE 或者 2.1.0.RELEASE 的版本。如果不是,请更正到 2.0.6.RELEASE 版本。 + +以下步骤向您展示了如何将一个服务注册到 Nacos。 + +1. pom.xml的配置。一个完整的 pom.xml 配置如下所示: +[source, xml] +---- + + + 4.0.0 + + open.source.test + nacos-discovery-test + 1.0-SNAPSHOT + nacos-discovery-test + + + org.springframework.boot + spring-boot-starter-parent + 2.0.6.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + + + + + + org.springframework.cloud + spring-cloud-dependencies + Finchley.SR1 + pom + import + + + org.springframework.cloud + spring-cloud-alibaba-dependencies + 0.2.0.RELEASE + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + +---- + +2. application.propertie配置。一些关于 Nacos 基本的配置也必须在 application.properties(也可以是application.yaml)配置,如下所示: + +application.propertoes +[source,properties] +---- +server.port=8081 +spring.application.name=nacos-producer +spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 +management.endpoints.web.exposure.include=* +---- + + +NOTE: 如果不想使用 Nacos 作为您的服务注册与发现,可以将 `spring.cloud.nacos.discovery` 设置为 `false`。 + +3. 启动 Provider 示例。如下所示: +[source,java,indent=0] +---- +@SpringBootApplication +@EnableDiscoveryClient +public class NacosProviderDemoApplication { + + public static void main(String[] args) { + SpringApplication.run(NacosProducerDemoApplication.class, args); + } + + @RestController + public class EchoController { + @GetMapping(value = "/echo/{string}") + public String echo(@PathVariable String string) { + return "Hello Nacos Discovery " + string; + } + } +} +---- + +这个时候你就可以在 Nacos的控制台上看到注册上来的服务信息了。 + +NOTE: 再启动 Provider 应用之前 请先将 Nacos 服务启动。具体启动方式可参考 https://nacos.io/zh-cn/docs/quick-start.html[Naco 官网]。 + +=== 服务的 EndPoint + +spring-cloud-starter-alibaba-nacos-discovery 在实现的时候提供了一个EndPoint,EndPoint的访问地址为`http://ip:port/actuator/nacos-discovery`。 +EndPoint 的信息主要提供了两类: + + 1. subscribe: 显示了当前有哪些服务订阅者 + 2、NacosDiscoveryProperties: 显示了当前服务实例关于 Nacos 的基础配置 + +一个服务实例访问 EndPoint 的信息如下所示: + +[source, json] +---- +{ + "subscribe": [ + { + "jsonFromServer": "", + "name": "nacos-provider", + "clusters": "", + "cacheMillis": 10000, + "hosts": [ + { + "instanceId": "30.5.124.156#8081#DEFAULT#nacos-provider", + "ip": "30.5.124.156", + "port": 8081, + "weight": 1.0, + "healthy": true, + "enabled": true, + "cluster": { + "serviceName": null, + "name": null, + "healthChecker": { + "type": "TCP" + }, + "defaultPort": 80, + "defaultCheckPort": 80, + "useIPPort4Check": true, + "metadata": { + + } + }, + "service": null, + "metadata": { + + } + } + ], + "lastRefTime": 1541755293119, + "checksum": "e5a699c9201f5328241c178e804657e11541755293119", + "allIPs": false, + "key": "nacos-producer", + "valid": true + } + ], + "NacosDiscoveryProperties": { + "serverAddr": "127.0.0.1:8848", + "endpoint": "", + "namespace": "", + "logName": "", + "service": "nacos-provider", + "weight": 1.0, + "clusterName": "DEFAULT", + "metadata": { + + }, + "registerEnabled": true, + "ip": "30.5.124.201", + "networkInterface": "", + "port": 8082, + "secure": false, + "accessKey": "", + "secretKey": "" + } +} +---- + +=== 启动一个 Consumer 应用 + +Consumer 的应用可能还没像启动一个 Provider 应用那么简单。因为在 Consumer 端需要去调用 Provider 端提供的REST 服务。例子中我们使用最原始的一种方式, +即显示的使用 LoadBalanceClient 和 RestTemolate 结合的方式来访问。 +pom.xml 和 application.properties 的配置可以参考 1.2 小结。启动一个 Consumer应用的示例代码如下所示: + +NOTE: 通过带有负载均衡的RestTemplate 和 FeignClient 也是可以访问的。 + +[source, java] +---- +@SpringBootApplication +@EnableDiscoveryClient +public class NacosConsumerApp { + + @RestController + public class NacosController{ + + @Autowired + private LoadBalancerClient loadBalancerClient; + @Autowired + private RestTemplate restTemplate; + + @Value("${spring.application.name}") + private String appName; + + @GetMapping("/echo/app-name") + public String echoAppName(){ + //使用 LoadBalanceClient 和 RestTemolate 结合的方式来访问 + ServiceInstance serviceInstance = loadBalancerClient.choose("nacos-provider"); + String url = String.format("http://%s:%s/echo/%s",serviceInstance.getHost(),serviceInstance.getPort(),appName); + System.out.println("request url:"+url); + return restTemplate.getForObject(url,String.class); + } + + } + + //实例化 RestTemplate 实例 + @Bean + public RestTemplate restTemplate(){ + + return new RestTemplate(); + } + + public static void main(String[] args) { + + SpringApplication.run(NacosConsumerApp.class,args); + } +} +---- + +这个例子中我们注入了一个 LoadBalancerClient 的实例,并且手动的实例化一个 RestTemplate,同时将 `spring.application.name` 的配置值 注入到应用中来, +目的是调用 Provider 提供的服务时,希望将当前配置的应用名给显示出来。 + +NOTE: 再启动 Consumer 应用之前 请先将 Nacos 服务启动。具体启动方式可参考 https://nacos.io/zh-cn/docs/quick-start.html[Naco 官网]。 + +启动后,访问 Consumer 提供出来的 `http://ip:port/echo/app-name` 接口。我这里测试启动的 port是 8082。访问结果如下所示: + + 访问地址:http://127.0.0.1:8082/echo/app-name + 访问结果:Hello Nacos Discovery nacos-consumer + + +== 2. 关于 Nacos Starter 更多的配置项信息 + +更多关于 spring-cloud-starter-alibaba-nacos-discovery starter 的配置项如下所示 + +:frame: topbot +[width="60%",options="header"] +|==== +^|配置项 ^|Key ^|默认值 ^|说明 +|`服务端地址`|`spring.cloud.nacos.discovery.server-addr`|`无`| `Nacos Server 启动监听的ip地址和端口` +|`服务名`|`spring.cloud.nacos.discovery.service`|`${spring.application.name}`|`给当前的服务命名` +|`权重`|`spring.cloud.nacos.discovery.weight`|`1`|`取值范围 1 到 100,数值越大,权重越大` +|`网卡名`|`spring.cloud.nacos.discovery.network-interface`|`无`|`当IP未配置时,注册的IP为此网卡所对应的IP地址,如果此项也未配置,则默认取第一块网卡的地址` +|`注册的IP地址`|`spring.cloud.nacos.discovery.ip`|`无`|`优先级最高` +|`注册的端口`|`spring.cloud.nacos.discovery.port`|`-1`|`默认情况下不用配置,会自动探测` +|`命名空间`|`spring.cloud.nacos.discovery.namespace`|`无`|`常用场景之一是不同环境的注册的区分隔离,例如开发测试环境和生产环境的资源(如配置、服务)隔离等。` +|`AccessKey`|`spring.cloud.nacos.discovery.access-key`|`无`|`当要上阿里云时,阿里云上面的一个云账号名` +|`SecretKey`|`spring.cloud.nacos.discovery.secret-key`|`无`|`当要上阿里云时,阿里云上面的一个云账号密码` +|`Metadata`|`spring.cloud.nacos.discovery.metadata`|`无`|`使用Map格式配置,用户可以根据自己的需要自定义一些和服务相关的元数据信息` +|`日志文件名`|`spring.cloud.nacos.discovery.log-name`|`无`| +|`接入点`|`spring.cloud.nacos.discovery.enpoint`|`UTF-8`|`地域的某个服务的入口域名,通过此域名可以动态地拿到服务端地址` +|`是否集成Ribbon`|`ribbon.nacos.enabled`|`true`|`一般都设置成true即可` +|==== + From a40d6925f5c5848291d40618cbacfaef43742390 Mon Sep 17 00:00:00 2001 From: pengbingting Date: Wed, 14 Nov 2018 17:41:42 +0800 Subject: [PATCH 10/23] =?UTF-8?q?=E8=AE=A2=E6=AD=A3=20properties=E7=9A=84?= =?UTF-8?q?=E6=8B=BC=E5=86=99=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/asciidoc-zh/nacos-discovery.adoc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc index d4a9a4c63..e6824aef3 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc @@ -1,7 +1,7 @@ = Spring Cloud Alibaba Nacos Discovery -该项目通过自动配置以及其他 Spring 编程模型的习惯用法为Spring Boot 应用程序在服务注册与发现方面提供和Nacos的无缝集成。 -通过一些简单的注解,您可以快速来注册一个服务,并使用经过双十一考验的Nacos组件来作为大规模分布式系统的服务注册中心。 +该项目通过自动配置以及其他 Spring 编程模型的习惯用法为 Spring Boot 应用程序在服务注册与发现方面提供和 Nacos 的无缝集成。 +通过一些简单的注解,您可以快速来注册一个服务,并使用经过双十一考验的 Nacos 组件来作为大规模分布式系统的服务注册中心。 == 1. 服务注册发现: Nacos Discovery Starter @@ -119,8 +119,7 @@ Spring Cloud 的 Finchley.SR1 版本最佳实践的 Spring Boot 版本是 2.0.6. ---- -2. application.propertie配置。一些关于 Nacos 基本的配置也必须在 application.properties(也可以是application.yaml)配置,如下所示: - +2. application.properties 配置。一些关于 Nacos 基本的配置也必须在 application.properties(也可以是application.yaml)配置,如下所示: application.propertoes [source,properties] ---- From 4644c65682706445c602a424a886c6447889035b Mon Sep 17 00:00:00 2001 From: pengbingting Date: Wed, 14 Nov 2018 17:42:57 +0800 Subject: [PATCH 11/23] =?UTF-8?q?=E8=AE=A2=E6=AD=A3=20properties=E7=9A=84?= =?UTF-8?q?=E6=8B=BC=E5=86=99=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/asciidoc-zh/nacos-discovery.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc index e6824aef3..f54b72920 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc @@ -120,7 +120,7 @@ Spring Cloud 的 Finchley.SR1 版本最佳实践的 Spring Boot 版本是 2.0.6. ---- 2. application.properties 配置。一些关于 Nacos 基本的配置也必须在 application.properties(也可以是application.yaml)配置,如下所示: -application.propertoes +application.properties [source,properties] ---- server.port=8081 From 6a204c4a98a25bd61669ef1c28a1661075a4619f Mon Sep 17 00:00:00 2001 From: pengbingting Date: Wed, 14 Nov 2018 17:45:55 +0800 Subject: [PATCH 12/23] =?UTF-8?q?=E8=AE=A2=E6=AD=A3=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/asciidoc-zh/nacos-discovery.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc index f54b72920..7d971cad8 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc @@ -159,10 +159,10 @@ NOTE: 再启动 Provider 应用之前 请先将 Nacos 服务启动。具体启 === 服务的 EndPoint -spring-cloud-starter-alibaba-nacos-discovery 在实现的时候提供了一个EndPoint,EndPoint的访问地址为`http://ip:port/actuator/nacos-discovery`。 +spring-cloud-starter-alibaba-nacos-discovery 在实现的时候提供了一个EndPoint,EndPoint的访问地址为 `http://ip:port/actuator/nacos-discovery`。 EndPoint 的信息主要提供了两类: - 1. subscribe: 显示了当前有哪些服务订阅者 + 1、subscribe: 显示了当前有哪些服务订阅者 2、NacosDiscoveryProperties: 显示了当前服务实例关于 Nacos 的基础配置 一个服务实例访问 EndPoint 的信息如下所示: From 231c15bfe1d6c6f2e2a1a5adaf82914e65ad0cf8 Mon Sep 17 00:00:00 2001 From: pengbingting Date: Wed, 14 Nov 2018 17:48:35 +0800 Subject: [PATCH 13/23] =?UTF-8?q?=E8=AE=A2=E6=AD=A3=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/asciidoc-zh/nacos-discovery.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc index 7d971cad8..4aad69351 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc @@ -285,7 +285,7 @@ public class NacosConsumerApp { 这个例子中我们注入了一个 LoadBalancerClient 的实例,并且手动的实例化一个 RestTemplate,同时将 `spring.application.name` 的配置值 注入到应用中来, 目的是调用 Provider 提供的服务时,希望将当前配置的应用名给显示出来。 -NOTE: 再启动 Consumer 应用之前 请先将 Nacos 服务启动。具体启动方式可参考 https://nacos.io/zh-cn/docs/quick-start.html[Naco 官网]。 +NOTE: 在启动 Consumer 应用之前请先将 Nacos 服务启动好。具体启动方式可参考 https://nacos.io/zh-cn/docs/quick-start.html[Nacos 官网]。 启动后,访问 Consumer 提供出来的 `http://ip:port/echo/app-name` 接口。我这里测试启动的 port是 8082。访问结果如下所示: @@ -295,7 +295,7 @@ NOTE: 再启动 Consumer 应用之前 请先将 Nacos 服务启动。具体启 == 2. 关于 Nacos Starter 更多的配置项信息 -更多关于 spring-cloud-starter-alibaba-nacos-discovery starter 的配置项如下所示 +更多关于 spring-cloud-starter-alibaba-nacos-discovery 的 starter 配置项如下所示: :frame: topbot [width="60%",options="header"] From e763b479be118a0fe133ce099e588d2a06f15124 Mon Sep 17 00:00:00 2001 From: pbting <314226532@qq.com> Date: Wed, 14 Nov 2018 18:00:23 +0800 Subject: [PATCH 14/23] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E4=B8=80=E8=A1=8C?= =?UTF-8?q?=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/asciidoc-zh/nacos-discovery.adoc | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc index 4aad69351..388e68f67 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc @@ -292,7 +292,6 @@ NOTE: 在启动 Consumer 应用之前请先将 Nacos 服务启动好。具体启 访问地址:http://127.0.0.1:8082/echo/app-name 访问结果:Hello Nacos Discovery nacos-consumer - == 2. 关于 Nacos Starter 更多的配置项信息 更多关于 spring-cloud-starter-alibaba-nacos-discovery 的 starter 配置项如下所示: From 005146020660f4124067a2c259927951739db07c Mon Sep 17 00:00:00 2001 From: pbting <314226532@qq.com> Date: Thu, 15 Nov 2018 10:52:18 +0800 Subject: [PATCH 15/23] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Nacos=20Discovery=20?= =?UTF-8?q?=E5=88=B0=20Reference=20=E7=9B=AE=E5=BD=95=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-zh.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++++---- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 5 deletions(-) diff --git a/README-zh.md b/README-zh.md index c6afae181..27d5895ef 100644 --- a/README-zh.md +++ b/README-zh.md @@ -1,13 +1,13 @@ # Spring Cloud Alibaba -Spring Cloud Alibaba 致力于提供分布式应用服务开发的一站式解决方案。此项目包含开发分布式应用服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发分布式应用服务。 +Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案。此项目包含开发分布式应用微服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发分布式应用服务。 -依托 Spring Cloud Alibaba,您只需要添加一些注解和少量配置,就可以将 Spring Cloud 应用接入阿里分布式应用解决方案,通过阿里中间件来迅速搭建分布式应用系统。 +依托 Spring Cloud Alibaba,您只需要添加一些注解和少量配置,就可以将 Spring Cloud 应用接入阿里微服务解决方案,通过阿里中间件来迅速搭建分布式应用系统。 ## 主要功能 -* **服务限流降级**:默认支持为 HTTP 服务的提供限流保护,也支持添加注解实现方法的自定义限流降级,且支持动态修改限流降级规则。 +* **服务限流降级**:默认支持 Servlet、RestTemplate、Dubbo 和 RocketMQ 限流降级功能的接入,可以在运行时通过控制台实时修改限流降级规则,还支持查看限流降级 Metrics 监控。 * **服务注册与发现**:适配 Spring Cloud 服务注册与发现标准,默认集成了 Ribbon 的支持。 * **分布式配置管理**:支持分布式系统中的外部化配置,配置更改时自动刷新。 * **阿里云对象存储**:阿里云提供的海量、安全、低成本、高可靠的云存储服务。支持在任何应用、任何时间、任何地点存储和访问任意类型的数据。 @@ -38,6 +38,52 @@ Spring Cloud 使用 Maven 来构建,最快的使用方式是将本项目clone ## 如何使用 +### 如何引入依赖 +项目已经发布了第一个版本,版本 0.2.0.RELEASE 对应的是 Spring Boot 2.x 版本,版本 0.1.0.RELEASE 对应的是 Spring Boot 1.x 版本。 + +如果需要使用已发布的版本,在 `dependencyManagement` 中添加如下配置。 + + + + + org.springframework.cloud + spring-cloud-alibaba-dependencies + 0.2.0.RELEASE + pom + import + + + + +然后再 `dependencies` 中添加自己所需使用的依赖即可使用。 + +如果您想体验最新的 BUILD-SNAPSHOT 的新功能,则可以将版本换成最新的版本,但是需要在 pom.xml 中配置 Spring BUILDSNAPSHOT 仓库,**注意: SNAPSHOT 版本随时可能更新** + + + + spring-snapshot + Spring Snapshot Repository + https://repo.spring.io/snapshot + + true + + + + + +### Reference Doc + +[目录](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-docs/src/main/asciidoc-zh/spring-cloud-alibaba.adoc) + +[Nacos Config](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc) + +[Nacos Discovery](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc) + +[ACM](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-docs/src/main/asciidoc-zh/acm.adoc) + + +## 演示 Demo + 为了演示如何使用,Spring Cloud Alibaba 项目包含了一个子模块`spring-cloud-alibaba-examples`。此模块中提供了演示用的 example ,您可以阅读对应的 example 工程下的 readme 文档,根据里面的步骤来体验。 Example 列表: @@ -50,6 +96,10 @@ Example 列表: [AliCloud OSS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/oss-example/readme-zh.md) +[AliCloud ANS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/ans-example/ans-provider-example/readme-zh.md) + +[AliCloud ACM Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/acm-example/acm-local-example/readme-zh.md) + ## 版本管理规范 项目的版本号格式为 x.x.x 的形式,其中 x 的数值类型为数字,从0开始取值,且不限于 0~9 这个范围。项目处于孵化器阶段时,第一位版本号固定使用0,即版本号为 0.x.x 的格式。 @@ -70,4 +120,4 @@ spring-cloud-alibaba@googlegroups.com,欢迎通过此邮件列表讨论与 spr ### 钉钉群 -![DingQR](https://cdn.nlark.com/lark/0/2018/png/64647/1535108150178-409a1689-437f-495b-8dcb-b667ccb32f85.png) +![DingQR](https://cdn.nlark.com/lark/0/2018/png/64647/1535108150178-409a1689-437f-495b-8dcb-b667ccb32f85.png) \ No newline at end of file diff --git a/README.md b/README.md index c69092a13..e81d27e84 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,53 @@ Spring Cloud uses Maven for most build-related activities, and you should be abl ./mvnw install -## How to use +## How to Use + +### Add maven dependency +Version 0.2.0.RELEASE is compatible with the Spring Boot 2.0.x line. Version 0.1.0.RELEASE is compatible with the Spring Boot 1.x line. + +These artifacts are available from Maven Central and Spring Release repository via BOM: + + + + + org.springframework.cloud + spring-cloud-alibaba-dependencies + 0.2.0.RELEASE + pom + import + + + + +add the module in `dependencies`. + +If you want to use the latest BUILD-SNAPSHOT version, add `Spring Snapshot Repository` in pom.xml , **Attention: BUILD-SNAPSHOT may be updated in any time** + + + + spring-snapshot + Spring Snapshot Repository + https://repo.spring.io/snapshot + + true + + + + + +### Reference Doc + +[Contents](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-docs/src/main/asciidoc-zh/spring-cloud-alibaba.adoc) + +[Nacos Config](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc) + +[Nacos Discovery](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc) + +[ACM](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-docs/src/main/asciidoc-zh/acm.adoc) + + +## Examples A `spring-cloud-alibaba-examples` module is included in our project for you to get started with Spring Cloud Alibaba quickly. It contains an example, and you can refer to the readme file in the example project for a quick walkthrough. From 698ee5a7c6a11c30feae11059d36a6e6dbea1da0 Mon Sep 17 00:00:00 2001 From: pbting <314226532@qq.com> Date: Thu, 15 Nov 2018 16:29:36 +0800 Subject: [PATCH 16/23] =?UTF-8?q?=E9=80=9A=E8=BF=87=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E5=BC=8F=E6=9D=A5=E9=85=8D=E7=BD=AENacos?= =?UTF-8?q?=E7=9A=84=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加说明通过域名的方式来配置Nacos的地址时需要注意的地方。 --- .../src/main/asciidoc-zh/nacos-config.adoc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc index b3f9fb5bd..c933352cd 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc @@ -117,10 +117,12 @@ spring-cloud-starter-alibaba-nacos-config 默认对文件扩展名为properties [source,properties] ---- spring.application.name=nacos-config -spring.cloud.nacos.config.server-addr=127.0.0.1:8848 +spring.cloud.nacos.config.server-addr=127.0.0.1:8848 spring.cloud.nacos.config.file-extension=yaml #显示的声明使用的文件扩展名 ---- +NOTE: 如果 spring.cloud.nacos.config.server-addr 使用的是域名,请写上域名以及监听的端口号,即使是默认的80也需要填上,因为当只配上了域名时会自动填上Nacos的默认端口8848。 + 2、在Nacos的控制台新增一个dataid为yaml为扩展名的配置,如下所示: [source,subs="normal"] From 1dfef15dee488db56df55c0ef068875e2362bce2 Mon Sep 17 00:00:00 2001 From: pbting <314226532@qq.com> Date: Thu, 15 Nov 2018 16:33:49 +0800 Subject: [PATCH 17/23] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E9=85=8D=E7=BD=AENacos=E6=9C=8D=E5=8A=A1=E7=AB=AF=E5=9C=B0?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加说明 使用域名配置Nacos服务端地址 --- .../src/main/asciidoc-zh/nacos-config.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc index c933352cd..e6c31e552 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc @@ -121,7 +121,7 @@ spring.cloud.nacos.config.server-addr=127.0.0.1:8848 spring.cloud.nacos.config.file-extension=yaml #显示的声明使用的文件扩展名 ---- -NOTE: 如果 spring.cloud.nacos.config.server-addr 使用的是域名,请写上域名以及监听的端口号,即使是默认的80也需要填上,因为当只配上了域名时会自动填上Nacos的默认端口8848。 +NOTE: 如果 spring.cloud.nacos.config.server-addr 使用的是域名,请写上域名以及监听的端口号,`请切记不用带上http:// 前缀以及 /nacos的后缀`,即使是默认的80也需要填上,因为当只配上了域名时会自动填上Nacos的默认端口8848。例如当你的域名是abc.com.nacos 时,监听的端口号是80,那么`spring.cloud.nacos.config.server-addr` 的配置是 `abc.com.nacos:80`。 2、在Nacos的控制台新增一个dataid为yaml为扩展名的配置,如下所示: From 1776055480acbc2b5d48879dedf8707a103ef207 Mon Sep 17 00:00:00 2001 From: pbting <314226532@qq.com> Date: Thu, 15 Nov 2018 16:50:38 +0800 Subject: [PATCH 18/23] =?UTF-8?q?=E6=9B=B4=E6=94=B9Nacos=20Config=20?= =?UTF-8?q?=E7=9A=84=20Reference=20=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/asciidoc-zh/nacos-config.adoc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc index b3f9fb5bd..6ac10942d 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc @@ -93,12 +93,17 @@ public class ProviderApplication { spring-cloud-starter-alibaba-nacos-config 对于Nacos服务端的基础配置没有默认值,因此在运行此Example 之前, 必须使用 bootstrap.properties 配置文件来配置Nacos Server地址,例如: +.bootstrap.properties [source,properties] ---- spring.application.name=nacos-config #注意,spring.application.name 必须要放在bootstrap.properties中 spring.cloud.nacos.config.server-addr=127.0.0.1:8848 ---- +NOTE: 注意当你使用域名的方式来访问 Nacos 时,`spring.cloud.nacos.config.server-addr` 配置的方式为 `域名:port`。 +例如 Nacos 的域名为abc.com.nacos,监听的端口为 80,则 `spring.cloud.nacos.config.server-addr=abc.com.nacos:80`。 +注意 80 端口不能省略。 + 启动这个Example,可以在控制台看到打印出的值正是在Nacos上预先配置好的值。 [source,subs="normal"] @@ -113,15 +118,17 @@ user name :nacos-config-properties; age: 90 spring-cloud-starter-alibaba-nacos-config 默认对文件扩展名为properties的支持,如果习惯使用yaml格式来作为应用中的基础配置,也是可以支持的。这个时候只需要完成以下两步: -1、在bootstrap.properties配置文件中显示的来声明使用的文件扩展名。如下所示 -[source,properties] +1、在bootstrap.yaml。如下所示 + +.bootstrap.yaml +[source,yaml] ---- -spring.application.name=nacos-config -spring.cloud.nacos.config.server-addr=127.0.0.1:8848 -spring.cloud.nacos.config.file-extension=yaml #显示的声明使用的文件扩展名 +spring.application.name: nacos-config +spring.cloud.nacos.config.server-addr: 127.0.0.1:8848 +spring.cloud.nacos.config.file-extension: yaml #显示的声明使用的文件扩展名 ---- -2、在Nacos的控制台新增一个dataid为yaml为扩展名的配置,如下所示: +2、在 Nacos 的控制台新增一个dataid为yaml为扩展名的配置,如下所示: [source,subs="normal"] ---- From e70ddab7178a952fe99319e6105bfad008156462 Mon Sep 17 00:00:00 2001 From: pbting <314226532@qq.com> Date: Thu, 15 Nov 2018 17:04:23 +0800 Subject: [PATCH 19/23] =?UTF-8?q?=E6=9B=B4=E6=94=B9Nacos=20Config=20?= =?UTF-8?q?=E7=9A=84=20Reference=20=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/asciidoc-zh/nacos-config.adoc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc index 6ac10942d..35ed14544 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc @@ -2,13 +2,13 @@ == 快速开始 -=== 基于properties的文件扩展名的配置方式 +=== 基于 dataid 为 properties 的文件扩展名配置方式 ==== Nacos 服务端初始化 1、启动Nacos Server。启动方式可见 https://nacos.io/zh-cn/docs/quick-start.html[Nacos 官网] -2、启动好Nacos之后,在Nacos添加如下的配置。注意data id是以 properties为扩展名,默认的文件扩展名方式。如下所示: +2、启动好Nacos之后,在Nacos添加如下的配置。注意dataid是以 properties为扩展名,默认的文件扩展名方式。如下所示: [source,subs="normal"] ---- @@ -91,7 +91,7 @@ public class ProviderApplication { } ---- -spring-cloud-starter-alibaba-nacos-config 对于Nacos服务端的基础配置没有默认值,因此在运行此Example 之前, 必须使用 bootstrap.properties 配置文件来配置Nacos Server地址,例如: +spring-cloud-starter-alibaba-nacos-config 对于 Nacos 服务端的基础配置没有默认值,因此在运行此Example 之前, 必须使用 bootstrap.properties 配置文件来配置Nacos Server地址,例如: .bootstrap.properties [source,properties] @@ -114,18 +114,17 @@ user name :nacos-config-properties; age: 90 2018-11 ---- -=== 基于yaml的文件扩展名的配置方式 +=== 基于 dataid 为 yaml 的文件扩展名配置方式 -spring-cloud-starter-alibaba-nacos-config 默认对文件扩展名为properties的支持,如果习惯使用yaml格式来作为应用中的基础配置,也是可以支持的。这个时候只需要完成以下两步: +spring-cloud-starter-alibaba-nacos-config 默认对 dateid 的文件扩展名是 properties。如果习惯使用yaml格式来作为应用中的基础配置,也是可以支持的。 +这个时候只需要完成以下两步: -1、在bootstrap.yaml。如下所示 +1、在应用的 bootstrap.properties 配置文件中显示的声明 dataid 文件扩展名。如下所示 .bootstrap.yaml [source,yaml] ---- -spring.application.name: nacos-config -spring.cloud.nacos.config.server-addr: 127.0.0.1:8848 -spring.cloud.nacos.config.file-extension: yaml #显示的声明使用的文件扩展名 +spring.cloud.nacos.config.file-extension=yaml ---- 2、在 Nacos 的控制台新增一个dataid为yaml为扩展名的配置,如下所示: From 118b546d7bd43f5d3a51c4730ee24b912911442b Mon Sep 17 00:00:00 2001 From: pbting <314226532@qq.com> Date: Thu, 15 Nov 2018 17:06:30 +0800 Subject: [PATCH 20/23] =?UTF-8?q?=E6=9B=B4=E6=94=B9Nacos=20Config=20?= =?UTF-8?q?=E7=9A=84=20Reference=20=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/asciidoc-zh/nacos-config.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc index 35ed14544..684f3f825 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-config.adoc @@ -121,7 +121,7 @@ spring-cloud-starter-alibaba-nacos-config 默认对 dateid 的文件扩展名是 1、在应用的 bootstrap.properties 配置文件中显示的声明 dataid 文件扩展名。如下所示 -.bootstrap.yaml +.bootstrap.properties [source,yaml] ---- spring.cloud.nacos.config.file-extension=yaml From cf1abefd200b4d05cfd6d9c53db1232982c46098 Mon Sep 17 00:00:00 2001 From: pbting <314226532@qq.com> Date: Thu, 15 Nov 2018 17:09:27 +0800 Subject: [PATCH 21/23] =?UTF-8?q?=E6=9B=B4=E6=94=B9Nacos=20=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E7=9A=84=E4=BE=9D=E8=B5=96=E7=9A=84=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spring-cloud-alibaba-dependencies/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-dependencies/pom.xml b/spring-cloud-alibaba-dependencies/pom.xml index 33b5ad6af..7a1f5c56e 100644 --- a/spring-cloud-alibaba-dependencies/pom.xml +++ b/spring-cloud-alibaba-dependencies/pom.xml @@ -18,7 +18,7 @@ 1.3.0-GA 3.1.0 - 0.3.0 + 0.4.0 1.0.8 0.1.1 4.0.1 From cf443d7af3000cd6b6d36cfcc670bebd9ee89529 Mon Sep 17 00:00:00 2001 From: xiaojing Date: Sat, 17 Nov 2018 22:18:47 +0800 Subject: [PATCH 22/23] update parent version --- spring-cloud-alibaba-nacos-config-server/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-cloud-alibaba-nacos-config-server/pom.xml b/spring-cloud-alibaba-nacos-config-server/pom.xml index eb5b48f4a..036e7025d 100644 --- a/spring-cloud-alibaba-nacos-config-server/pom.xml +++ b/spring-cloud-alibaba-nacos-config-server/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-alibaba - 0.2.0.BUILD-SNAPSHOT + 0.2.1.BUILD-SNAPSHOT ../pom.xml 4.0.0 @@ -60,4 +60,4 @@
- \ No newline at end of file + From a09d79bd2e95f0f7528c04ed9e846d0853003efd Mon Sep 17 00:00:00 2001 From: mercyblitz Date: Mon, 19 Nov 2018 16:18:33 +0800 Subject: [PATCH 23/23] Polish Config Server --- pom.xml | 11 +++++++++-- spring-cloud-alibaba-nacos-config-server/pom.xml | 1 + .../server/NacosConfigServerAutoConfiguration.java | 2 ++ .../server/bootstrap/NacosConfigServerBootstrap.java | 10 ++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 38ac083ca..1969d6283 100644 --- a/pom.xml +++ b/pom.xml @@ -55,6 +55,13 @@ hengyunabc hengyunabc@gmail.com + + mercyblitz + Mercy Ma + mercyblitz@gmail.com + Alibaba + https://github.com/mercyblitz + @@ -81,14 +88,14 @@ spring-cloud-alibaba-sentinel-datasource spring-cloud-alibaba-nacos-config spring-cloud-alibaba-nacos-discovery + spring-cloud-alibaba-nacos-config-server + spring-cloud-alicloud-context spring-cloud-alibaba-examples spring-cloud-alibaba-test spring-cloud-alibaba-docs spring-cloud-starter-alibaba spring-cloud-starter-alicloud spring-cloud-alicloud-oss - spring-cloud-alibaba-nacos-config-server - spring-cloud-alicloud-context spring-cloud-alicloud-acm spring-cloud-alicloud-ans diff --git a/spring-cloud-alibaba-nacos-config-server/pom.xml b/spring-cloud-alibaba-nacos-config-server/pom.xml index 036e7025d..9287892e8 100644 --- a/spring-cloud-alibaba-nacos-config-server/pom.xml +++ b/spring-cloud-alibaba-nacos-config-server/pom.xml @@ -12,6 +12,7 @@ org.springframework.cloud spring-cloud-alibaba-nacos-config-server + Spring Cloud Alibaba Nacos Config Server diff --git a/spring-cloud-alibaba-nacos-config-server/src/main/java/org/springframework/cloud/alibaba/nacos/config/server/NacosConfigServerAutoConfiguration.java b/spring-cloud-alibaba-nacos-config-server/src/main/java/org/springframework/cloud/alibaba/nacos/config/server/NacosConfigServerAutoConfiguration.java index 42461f239..74a4903dc 100644 --- a/spring-cloud-alibaba-nacos-config-server/src/main/java/org/springframework/cloud/alibaba/nacos/config/server/NacosConfigServerAutoConfiguration.java +++ b/spring-cloud-alibaba-nacos-config-server/src/main/java/org/springframework/cloud/alibaba/nacos/config/server/NacosConfigServerAutoConfiguration.java @@ -23,6 +23,7 @@ import org.springframework.cloud.config.server.EnableConfigServer; import org.springframework.cloud.config.server.config.ConfigServerAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; /** * Nacos Config Server Auto-Configuration @@ -35,6 +36,7 @@ import org.springframework.context.annotation.ComponentScan; "com.alibaba.nacos.config.server", }) @AutoConfigureBefore(ConfigServerAutoConfiguration.class) +@Configuration public class NacosConfigServerAutoConfiguration { @Bean diff --git a/spring-cloud-alibaba-nacos-config-server/src/test/java/org/springframework/cloud/alibaba/nacos/config/server/bootstrap/NacosConfigServerBootstrap.java b/spring-cloud-alibaba-nacos-config-server/src/test/java/org/springframework/cloud/alibaba/nacos/config/server/bootstrap/NacosConfigServerBootstrap.java index 68d92e7db..3e379457e 100644 --- a/spring-cloud-alibaba-nacos-config-server/src/test/java/org/springframework/cloud/alibaba/nacos/config/server/bootstrap/NacosConfigServerBootstrap.java +++ b/spring-cloud-alibaba-nacos-config-server/src/test/java/org/springframework/cloud/alibaba/nacos/config/server/bootstrap/NacosConfigServerBootstrap.java @@ -16,9 +16,11 @@ */ package org.springframework.cloud.alibaba.nacos.config.server.bootstrap; +import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.cloud.config.server.EnableConfigServer; +import org.springframework.context.annotation.Bean; /** * Nacos Config Server Bootstrap @@ -34,4 +36,12 @@ public class NacosConfigServerBootstrap { System.setProperty("nacos.standalone", "true"); SpringApplication.run(NacosConfigServerBootstrap.class); } + + @Bean + public ApplicationRunner applicationRunner() { + + return args -> { + System.out.println("Running..."); + }; + } }