Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringCloudAlibaba
提交
1fdf90cf
S
SpringCloudAlibaba
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringCloudAlibaba
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringCloudAlibaba
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
1fdf90cf
编写于
2月 12, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:工具类
上级
5de68e8a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
99 addition
and
32 deletion
+99
-32
nacos-server-common/pom.xml
nacos-server-common/pom.xml
+34
-10
nacos-server-common/src/main/java/com/kwan/springcloudalibaba/util/FileContains.java
...n/java/com/kwan/springcloudalibaba/util/FileContains.java
+5
-5
nacos-server-consumer/pom.xml
nacos-server-consumer/pom.xml
+1
-13
nacos-server-consumer/src/main/java/com/kwan/springcloudalibaba/controller/ConsumerUserController.java
...springcloudalibaba/controller/ConsumerUserController.java
+2
-2
nacos-server-sentinel-consumer/pom.xml
nacos-server-sentinel-consumer/pom.xml
+14
-2
nacos-server-sentinel-consumer/src/main/java/com/kwan/springcloudalibaba/SentinelConsumerApplication.java
.../kwan/springcloudalibaba/SentinelConsumerApplication.java
+23
-0
nacos-server-sentinel-consumer/src/main/java/com/kwan/springcloudalibaba/controller/SentinelController.java
...wan/springcloudalibaba/controller/SentinelController.java
+20
-0
未找到文件。
nacos-server-common/pom.xml
浏览文件 @
1fdf90cf
...
...
@@ -2,6 +2,18 @@
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<configuration>
<source>
8
</source>
<target>
8
</target>
</configuration>
</plugin>
</plugins>
</build>
<parent>
<groupId>
com.kwan.springcloudalibaba
</groupId>
<artifactId>
nacos-server-parent
</artifactId>
...
...
@@ -32,16 +44,28 @@
<groupId>
org.springframework
</groupId>
<artifactId>
spring-web
</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-openfeign</artifactId>-->
<!-- <version>2.0.0.RELEASE</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-hystrix</artifactId>-->
<!-- <version>1.4.7.RELEASE</version>-->
<!-- </dependency>-->
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
16.0.1
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.5.1
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.9
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
2.0.21
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
nacos-server-co
nsumer
/src/main/java/com/kwan/springcloudalibaba/util/FileContains.java
→
nacos-server-co
mmon
/src/main/java/com/kwan/springcloudalibaba/util/FileContains.java
浏览文件 @
1fdf90cf
package
com.kwan.springcloudalibaba.util
;
import
cn.hutool.core.date.StopWatch
;
import
com.alibaba.fastjson2.JSON
;
import
com.google.common.base.Charsets
;
import
com.google.common.io.Files
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.time.StopWatch
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
/**
* 字符串是否存在文件中
...
...
@@ -41,7 +41,7 @@ public class FileContains {
final
List
<
String
>
isNotExist
=
new
ArrayList
<>();
//获取picPath下面所有的文件名
final
List
<
String
>
picNames
=
getPicName
(
PIC_PATH
);
log
.
info
(
"图片总数为{}"
,
picNames
.
size
());
System
.
out
.
println
(
"图片总数为"
+
picNames
.
size
());
for
(
String
word
:
picNames
)
{
IS_EXIST
=
false
;
//指定类型的文件
...
...
@@ -54,10 +54,10 @@ public class FileContains {
deletePic
(
PIC_PATH
+
word
);
}
}
log
.
info
(
"不存在图片总数为{}"
,
isNotExist
.
size
());
System
.
out
.
println
(
"不存在图片总数为"
+
isNotExist
.
size
());
stopWatch
.
stop
();
//毫秒输出
log
.
info
(
String
.
valueOf
(
stopWatch
.
getTime
(
TimeUnit
.
MILLISECONDS
)));
System
.
out
.
println
(
JSON
.
toJSONString
(
stopWatch
.
getTaskInfo
(
)));
}
/**
...
...
nacos-server-consumer/pom.xml
浏览文件 @
1fdf90cf
...
...
@@ -2,17 +2,14 @@
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
com.kwan.springcloudalibaba
</groupId>
<artifactId>
nacos-server-parent
</artifactId>
<version>
1.0.0-SNAPSHOT
</version>
</parent>
<artifactId>
nacos-server-consumer
</artifactId>
<name>
nacos-server-consumer
</name>
<description>
nacos-server-consumer
</description>
<properties>
<java.version>
1.8
</java.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
...
...
@@ -20,7 +17,6 @@
<spring-boot.version>
2.3.7.RELEASE
</spring-boot.version>
<spring-cloud-alibaba.version>
2.2.2.RELEASE
</spring-cloud-alibaba.version>
</properties>
<dependencies>
<dependency>
<groupId>
com.kwan.springcloudalibaba
</groupId>
...
...
@@ -31,7 +27,6 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
...
...
@@ -49,10 +44,6 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-openfeign
</artifactId>
...
...
@@ -63,8 +54,5 @@
<artifactId>
spring-cloud-starter-netflix-ribbon
</artifactId>
<version>
2.0.0.RELEASE
</version>
</dependency>
</dependencies>
</project>
</project>
\ No newline at end of file
nacos-server-consumer/src/main/java/com/kwan/springcloudalibaba/controller/ConsumerUserController.java
浏览文件 @
1fdf90cf
...
...
@@ -23,7 +23,7 @@ public class ConsumerUserController {
@Autowired
private
RestTemplate
restTemplate
;
@Autowired
private
FeignUserService
computeClient
;
private
FeignUserService
feignUserService
;
@Autowired
private
DiscoveryClient
discoveryClient
;
...
...
@@ -85,7 +85,7 @@ public class ConsumerUserController {
*/
@GetMapping
(
value
=
"/{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
getUserById
(
@PathVariable
Integer
id
)
{
return
Result
.
ok
(
computeClient
.
selectOne
(
id
));
return
Result
.
ok
(
feignUserService
.
selectOne
(
id
));
}
...
...
nacos-server-sentinel-consumer/pom.xml
浏览文件 @
1fdf90cf
...
...
@@ -16,8 +16,8 @@
<dependencies>
<dependency>
<groupId>
com.kwan.springcloudalibaba
</groupId>
<artifactId>
nacos-server-
common
</artifactId>
<version>
1.0.0
</version>
<artifactId>
nacos-server-
feign-api
</artifactId>
<version>
1.0.0
-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
@@ -67,6 +67,18 @@
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-openfeign
</artifactId>
<version>
2.0.0.RELEASE
</version>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-ribbon
</artifactId>
<version>
2.0.0.RELEASE
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
nacos-server-sentinel-consumer/src/main/java/com/kwan/springcloudalibaba/SentinelConsumerApplication.java
浏览文件 @
1fdf90cf
package
com.kwan.springcloudalibaba
;
import
com.alibaba.cloud.nacos.ribbon.NacosRule
;
import
com.netflix.loadbalancer.IPing
;
import
com.netflix.loadbalancer.IRule
;
import
com.netflix.loadbalancer.PingUrl
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.annotation.Bean
;
/**
...
...
@@ -11,9 +18,25 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @version : 2.2.0
* @date : 2023/1/17 12:37
*/
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public
class
SentinelConsumerApplication
{
@Bean
public
IRule
randomRule
()
{
return
new
NacosRule
();
//nacos的策略
// return new RandomRule(); //随机
//return new RoundRobinRule(); //轮训
//return new BestAvailableRule();
//return new ZoneAvoidanceRule(); //新版本默认的策略
}
@Bean
public
IPing
iping
()
{
return
new
PingUrl
();
}
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SentinelConsumerApplication
.
class
,
args
);
}
...
...
nacos-server-sentinel-consumer/src/main/java/com/kwan/springcloudalibaba/controller/SentinelController.java
浏览文件 @
1fdf90cf
...
...
@@ -3,8 +3,10 @@ package com.kwan.springcloudalibaba.controller;
import
com.alibaba.csp.sentinel.annotation.SentinelResource
;
import
com.alibaba.csp.sentinel.slots.block.BlockException
;
import
com.kwan.springcloudalibaba.common.Result
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -19,6 +21,24 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping
(
"/sentinel"
)
public
class
SentinelController
{
@Autowired
private
FeignUserService
feignUserService
;
/**
* feign调用
* http://127.0.0.1:8085/nacos/consumer/1
* <p>
* http://localhost:9091/user/1
*
* @param id
* @return
*/
@GetMapping
(
value
=
"/{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
getUserById
(
@PathVariable
Integer
id
)
{
return
Result
.
ok
(
feignUserService
.
selectOne
(
id
));
}
/**
* 获取配置的变量
* http://localhost:8086/sentinel/nameInfo
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录