浏览代码

1.feat: company模块加入sentinel服务哨兵组件

Leslie 2 年之前
父节点
当前提交
595b253075

+ 6 - 5
hxgc-burst/src/main/java/com/hxgc/api/CompanyApi.java → hxgc-api/src/main/java/com/hxgc/api/CompanyApi.java

@@ -18,19 +18,20 @@ public interface CompanyApi {
     @PostMapping(value = "/save")
     public Map save(@RequestBody Jifen jifen);
 
-    @PostMapping(value = "/update")
-    public Map update(@RequestBody Jifen jifen);
-
+    // @PostMapping(value = "/update")
+    // public Map update(@RequestBody Jifen jifen);
+    //
     @GetMapping(value = "/delete")
-    public Map deleteById(Integer jifenId) ;
+    public Map deleteById(@RequestParam("jifenId") Integer jifenId) ;
 
 
     //注意传参问题 加上注解requestParam
     @GetMapping(value = "/{jifenId}")
     public Jifen findJifenById(@PathVariable Integer jifenId) ;
 
+    //多个参数时凭借url可能会出问题 加上注解 固定拼接对象
     @GetMapping(value = "/search")
-    public Jifen search(Integer uid,String type);
+    public Jifen search(@RequestParam("uid") Integer uid,@RequestParam("type") String type);
 
     @PostMapping(value = "/searchByEntity")
     public List<Jifen> searchMap(@RequestBody  Jifen jifen) ;

+ 17 - 0
hxgc-api/src/main/resources/bootstrap.yml

@@ -0,0 +1,17 @@
+spring:
+  profiles:
+    active: @env@
+  cloud:
+    nacos:
+      config:
+        server-addr: localhost:8848
+        namespace: @env@
+        group: DEFAULT_GROUP
+        username: nacos
+        password: nacos
+        # ${prefix}-${spring.profiles.active}.${file-extension}  拼接文件名
+        prefix: hxgc-burst
+        file-extension: yml
+        shared-configs: #加载共享配置文件
+          - common.yml
+        refreshable-dataids: common.yml #指定配置文件支持动态刷新

+ 5 - 0
hxgc-burst/pom.xml

@@ -70,6 +70,11 @@
             <artifactId>hxgc-entity</artifactId>
             <version>1.0-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>com.hxgc</groupId>
+            <artifactId>hxgc-api</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
 
     </dependencies>
 

+ 2 - 0
hxgc-burst/src/main/java/com/hxgc/BurstApp.java

@@ -10,6 +10,8 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
 @EnableDiscoveryClient
 //开启openfeign支持
 @EnableFeignClients
+//如果不是在同一个basepackages下 通过配置声明扫描
+// @EnableFeignClients(basePackages = {"com.xx.xx"})
 public class BurstApp {
     public static void main(String[] args) {
         SpringApplication.run(BurstApp.class,args);

+ 23 - 0
hxgc-burst/src/main/java/com/hxgc/controller/BurstController.java

@@ -41,5 +41,28 @@ public class BurstController {
 
     }
 
+    @RequestMapping("test03")
+    public Map test03(){
+
+        //远程调用服务
+        //url= http://hxgc-company/company/delete?jifenId=1
+        Map sas = companyApi.deleteById(1);
+
+        return sas;
+
+    }
+
+    @RequestMapping("test05")
+    public Jifen test05(){
+
+        //远程调用服务
+        //url= http://hxgc-company/company/delete?jifenId=1
+        Jifen sas = companyApi.search(1,"ss");
+
+        return sas;
+
+    }
+
+
 
 }

+ 14 - 1
hxgc-burst/src/main/resources/bootstrap.yml

@@ -14,4 +14,17 @@ spring:
         file-extension: yml
         shared-configs: #加载共享配置文件
           - common.yml
-        refreshable-dataids: common.yml #指定配置文件支持动态刷新
+        refreshable-dataids: common.yml #指定配置文件支持动态刷新
+ribbon:
+  eager-load:
+    enabled: true #当服务启动立即加载实例列表
+
+#feign:
+#  client:
+#    config:
+#      hxgc-company:
+#        connect-timeout: 1000
+#        read-timeout: 1  #设置响应的超时时间为1毫秒
+#      default: #设置默认的超时时间
+#        connect-timeout: 1000
+#        read-timeout: 2000

+ 4 - 0
hxgc-company/pom.xml

@@ -45,6 +45,10 @@
             <artifactId>hxgc-entity</artifactId>
             <version>1.0-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
+        </dependency>
 
     </dependencies>
 

+ 1 - 1
hxgc-company/src/main/java/com/hxgc/controller/CompanyController.java

@@ -57,7 +57,7 @@ public class CompanyController {
     }
 
 
-    @GetMapping(value = "/search")
+    @PostMapping(value = "/search")
     public Jifen search(Integer uid,String type) {
         System.out.println("uid:"+uid+"type:"+type);
         return new Jifen(uid, 12,type);

+ 5 - 0
hxgc-company/src/main/resources/bootstrap.yml

@@ -15,3 +15,8 @@ spring:
         shared-configs: #加载共享配置文件
           - common.yml
         refreshable-dataids: common.yml #指定配置文件支持动态刷新
+
+#    sentinel:
+#      transport:
+#        dashboard: http://localhost:8888
+#        port: 8719

+ 1 - 1
pom.xml

@@ -24,7 +24,7 @@
         <maven.compiler.source>8</maven.compiler.source>
         <maven.compiler.target>8</maven.compiler.target>
         <!-- 定义变量 -->
-        <env>sit</env>
+        <env>pro</env>
     </properties>
 
     <!--    父工程的职责:锁定版本    springboot、springcloud、springcloud-alibaba-->