1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00
This commit is contained in:
赵禹光 2019-08-09 15:02:58 +08:00
parent 60702b9874
commit ca23f7be58
2 changed files with 10 additions and 9 deletions

View File

@ -119,7 +119,7 @@ application.properties
[source,properties,indent=0] [source,properties,indent=0]
---- ----
server.port=8081 server.port=8081
spring.application.name=nacos-producer spring.application.name=nacos-provider
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.include=*
---- ----
@ -135,7 +135,7 @@ NOTE: 如果不想使用 Nacos 作为您的服务注册与发现,可以将 `sp
public class NacosProviderDemoApplication { public class NacosProviderDemoApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(NacosProducerDemoApplication.class, args); SpringApplication.run(NacosProviderDemoApplication.class, args);
} }
@RestController @RestController
@ -177,7 +177,7 @@ public class NacosConsumerApp {
@GetMapping("/echo/app-name") @GetMapping("/echo/app-name")
public String echoAppName(){ public String echoAppName(){
//使用 LoadBalanceClient 和 RestTemolate 结合的方式来访问 //使用 LoadBalanceClient 和 RestTemplate 结合的方式来访问
ServiceInstance serviceInstance = loadBalancerClient.choose("nacos-provider"); ServiceInstance serviceInstance = loadBalancerClient.choose("nacos-provider");
String url = String.format("http://%s:%s/echo/%s",serviceInstance.getHost(),serviceInstance.getPort(),appName); String url = String.format("http://%s:%s/echo/%s",serviceInstance.getHost(),serviceInstance.getPort(),appName);
System.out.println("request url:"+url); System.out.println("request url:"+url);
@ -261,7 +261,7 @@ Endpoint 暴露的 json 中包含了两种属性:
"lastRefTime": 1541755293119, "lastRefTime": 1541755293119,
"checksum": "e5a699c9201f5328241c178e804657e11541755293119", "checksum": "e5a699c9201f5328241c178e804657e11541755293119",
"allIPs": false, "allIPs": false,
"key": "nacos-producer", "key": "nacos-provider",
"valid": true "valid": true
} }
], ],
@ -306,7 +306,7 @@ Endpoint 暴露的 json 中包含了两种属性:
|SecretKey|`spring.cloud.nacos.discovery.secret-key`||当要上阿里云时,阿里云上面的一个云账号密码 |SecretKey|`spring.cloud.nacos.discovery.secret-key`||当要上阿里云时,阿里云上面的一个云账号密码
|Metadata|`spring.cloud.nacos.discovery.metadata`||使用Map格式配置用户可以根据自己的需要自定义一些和服务相关的元数据信息 |Metadata|`spring.cloud.nacos.discovery.metadata`||使用Map格式配置用户可以根据自己的需要自定义一些和服务相关的元数据信息
|日志文件名|`spring.cloud.nacos.discovery.log-name`|| |日志文件名|`spring.cloud.nacos.discovery.log-name`||
|集群|`spring.cloud.nacos.discovery.cluster-name`|`DEFAULT`|配置成Nacos集群名称 |集群|`spring.cloud.nacos.discovery.cluster-name`|`DEFAULT`|Nacos集群名称
|接入点|`spring.cloud.nacos.discovery.endpoint`||地域的某个服务的入口域名,通过此域名可以动态地拿到服务端地址 |接入点|`spring.cloud.nacos.discovery.endpoint`||地域的某个服务的入口域名,通过此域名可以动态地拿到服务端地址
|是否集成Ribbon|`ribbon.nacos.enabled`|`true`|一般都设置成true即可 |是否集成Ribbon|`ribbon.nacos.enabled`|`true`|一般都设置成true即可
|是否开启Nacos Watch|`spring.cloud.nacos.discovery.watch.enabled`|`true`|可以设置成false来关闭 watch |是否开启Nacos Watch|`spring.cloud.nacos.discovery.watch.enabled`|`true`|可以设置成false来关闭 watch

View File

@ -119,7 +119,7 @@ application.properties
[source,properties] [source,properties]
---- ----
server.port=8081 server.port=8081
spring.application.name=nacos-producer spring.application.name=nacos-provider
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.include=*
---- ----
@ -135,7 +135,7 @@ NOTE: If you do not want to use Nacos for service registration and discovery, yo
public class NacosProviderDemoApplication { public class NacosProviderDemoApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(NacosProducerDemoApplication.class, args); SpringApplication.run(NacosProviderDemoApplication.class, args);
} }
@RestController @RestController
@ -179,7 +179,7 @@ public class NacosConsumerApp {
@GetMapping("/echo/app-name") @GetMapping("/echo/app-name")
public String echoAppName(){ public String echoAppName(){
//Access through the combination of LoadBalanceClient and RestTemolate //Access through the combination of LoadBalanceClient and RestTemplate
ServiceInstance serviceInstance = loadBalancerClient.choose("nacos-provider"); ServiceInstance serviceInstance = loadBalancerClient.choose("nacos-provider");
String path = String.format("http://%s:%s/echo/%s",serviceInstance.getHost(),serviceInstance.getPort(),appName); String path = String.format("http://%s:%s/echo/%s",serviceInstance.getHost(),serviceInstance.getPort(),appName);
System.out.println("request path:" +path); System.out.println("request path:" +path);
@ -264,7 +264,7 @@ The followings shows how a service instance accesses the Endpoint:
"lastRefTime": 1541755293119, "lastRefTime": 1541755293119,
"checksum": "e5a699c9201f5328241c178e804657e11541755293119", "checksum": "e5a699c9201f5328241c178e804657e11541755293119",
"allIPs": false, "allIPs": false,
"key": "nacos-producer", "key": "nacos-provider",
"valid": true "valid": true
} }
], ],
@ -309,6 +309,7 @@ The following shows the other configurations of the starter of Nacos Discovery:
|SecretKey|`spring.cloud.nacos.discovery.secret-key`||Alibaba Cloud account secretkey |SecretKey|`spring.cloud.nacos.discovery.secret-key`||Alibaba Cloud account secretkey
|Metadata|`spring.cloud.nacos.discovery.metadata`||You can define some of the metadata for your services in the Map format |Metadata|`spring.cloud.nacos.discovery.metadata`||You can define some of the metadata for your services in the Map format
|Log file name|`spring.cloud.nacos.discovery.log-name`|| |Log file name|`spring.cloud.nacos.discovery.log-name`||
|Cluster Name|`spring.cloud.nacos.discovery.cluster-name`|`DEFAULT`|Cluster name of Nacos
|Endpoint|`spring.cloud.nacos.discovery.endpoint`||The domain name of a certain service in a specific region. You can retrieve the server address dynamically with this domain name |Endpoint|`spring.cloud.nacos.discovery.endpoint`||The domain name of a certain service in a specific region. You can retrieve the server address dynamically with this domain name
|Integrate Ribbon or not|`ribbon.nacos.enabled`|`true`|Set to true in most cases |Integrate Ribbon or not|`ribbon.nacos.enabled`|`true`|Set to true in most cases
|Enable Nacos Watch|`spring.cloud.nacos.discovery.watch.enabled`|`true`|set to false to close watch |Enable Nacos Watch|`spring.cloud.nacos.discovery.watch.enabled`|`true`|set to false to close watch