提供者微服务示例在项目中添加一个provider-service模块 , 在提供者微服务的pom依赖中添加父Maven项目的依赖、 Web 服务依赖、polaris服务注册依赖
<parent><groupId>cn.itxs</groupId><artifactId>spring-cloud-tencent-demo</artifactId><version>1.0-SNAPSHOT</version></parent><!-- 简单的 Spring Cloud Web 依赖 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- 引入 Spring Cloud Tencent 的服务注册发现依赖 --><dependency><groupId>com.tencent.cloud</groupId><artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId></dependency>
在provider-service的 resources 目录下创建 application.yml 文件 , 并按照如下进行配置
server:port: 28888spring:application:name: provider-servicecloud:polaris:# 配置polaris servre地址address: grpc://192.168.5.52:8091discovery:enabled: truestat:enabled: trueport: 28082
创建提供者微服务演示控制器ProviderHelloController.java
package cn.itxs.controller;import com.tencent.cloud.polaris.PolarisDiscoveryProperties;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class ProviderHelloController {private final PolarisDiscoveryProperties properties;ProviderHelloController(PolarisDiscoveryProperties properties) {this.properties = properties;}@RequestMapping("/hello/{val}")public String echo(@PathVariable String val) {return "Hello PolarisMesh,this is it xiao shen," + val + ", I'm " + properties.getService();}}
启动类ProviderApplication.java
package cn.itxs;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class ProviderApplication{public static void main(String[] args) {SpringApplication.run(ProviderApplication.class, args);}}
启动提供者微服务ProviderApplication
![鹅长微服务发现与治理巨作PolarisMesh实践-上](http://shimg.jingyanzongjie.com/230727/012403J55-10.png)
文章插图
查看控制台页面服务列表可以看到提供者微服务已经注册到北极星中default命名空间
![鹅长微服务发现与治理巨作PolarisMesh实践-上](http://shimg.jingyanzongjie.com/230727/0124033424-11.png)
文章插图
消费者微服务示例与上面服务提供类似 , 在项目中添加一个consumer-service模块 , 在消费者微服务的pom依赖中添加父Maven项目的依赖、 Web 服务依赖、polaris服务注册依赖
<parent><groupId>cn.itxs</groupId><artifactId>spring-cloud-tencent-demo</artifactId><version>1.0-SNAPSHOT</version></parent><dependencies><!-- 简单的 Spring Cloud Web 依赖 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- 引入 Spring Cloud Tencent 的服务注册发现依赖 --><dependency><groupId>com.tencent.cloud</groupId><artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId></dependency><!-- 引入 Feign 依赖实现 Feign 调用 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency></dependencies>
在consumer-service的 resources 目录下创建 application.yml 文件 , 并按照如下进行配置server:port: 38888spring:application:name: consumer-servicecloud:polaris:address: grpc://192.168.5.52:8091discovery:enabled: truestat:enabled: trueport: 38082
经验总结扩展阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 结婚的微信祝福句子
- 四十八 SpringCloud微服务实战——搭建企业级开发框架:【移动开发】整合uni-app搭建移动端快速开发框架-使用第三方UI框架
- 结婚的微博祝福句子
- 微信进去钱包怎么设置密码 微信进去钱包怎么设置密码保护
- Dapr实现.Net Grpc服务之间的发布和订阅,并采用WebApi类似的事件订阅方式
- Silky微服务框架之模块
- 国庆节微信祝福语简短
- 木签子可以放微波炉吗
- 一路向阳的微信签名 简短的签名很走心
- 一篇文章带你了解轻量级Web服务器——Nginx简单入门