Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringCloud-study
提交
cf53e5fa
S
SpringCloud-study
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringCloud-study
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringCloud-study
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
cf53e5fa
编写于
1月 13, 2023
作者:
Q
qinyingjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:添加consul
上级
f6fc046e
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
136 addition
and
128 deletion
+136
-128
pom.xml
pom.xml
+1
-0
springcloud-service-consul/pom.xml
springcloud-service-consul/pom.xml
+45
-0
springcloud-service-consul/src/main/java/com/kwan/springcloud/ConsulApplication.java
...src/main/java/com/kwan/springcloud/ConsulApplication.java
+15
-0
springcloud-service-consul/src/main/java/com/kwan/springcloud/controller/ConsulController.java
...ava/com/kwan/springcloud/controller/ConsulController.java
+25
-0
springcloud-service-consul/src/main/resources/application.yaml
...gcloud-service-consul/src/main/resources/application.yaml
+11
-0
springcloud-service-consul/src/test/java/com/kwan/springcloud/PortalApplicationTests.java
...est/java/com/kwan/springcloud/PortalApplicationTests.java
+13
-0
springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java
.../kwan/springcloud/controller/KwanGoodsInfoController.java
+1
-1
springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java
.../kwan/springcloud/controller/KwanGoodsInfoController.java
+1
-1
springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java
.../kwan/springcloud/controller/KwanGoodsInfoController.java
+1
-1
springcloud-service-portal/src/main/java/com/kwan/springcloud/controller/PortalController.java
...ava/com/kwan/springcloud/controller/PortalController.java
+6
-0
springcloud-service-zuul/pom.xml
springcloud-service-zuul/pom.xml
+1
-2
springcloud-service-zuul/src/main/java/com/kwan/springcloud/GoodsServiceFallBackProvider.java
...va/com/kwan/springcloud/GoodsServiceFallBackProvider.java
+0
-72
springcloud-service-zuul/src/main/java/com/kwan/springcloud/filter/MyZuulFilter.java
...c/main/java/com/kwan/springcloud/filter/MyZuulFilter.java
+0
-49
springcloud-service-zuul/src/main/resources/application.yaml
springcloud-service-zuul/src/main/resources/application.yaml
+16
-2
未找到文件。
pom.xml
浏览文件 @
cf53e5fa
...
...
@@ -34,6 +34,7 @@
<module>
springcloud-service-config-client
</module>
<module>
springcloud-service-feign
</module>
<module>
springcloud-service-zuul
</module>
<module>
springcloud-service-consul
</module>
<module>
springcloud-service-eureka
</module>
</modules>
...
...
springcloud-service-consul/pom.xml
0 → 100644
浏览文件 @
cf53e5fa
<?xml version="1.0" encoding="UTF-8"?>
<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.springcloud
</groupId>
<artifactId>
springcloud-service-parent
</artifactId>
<version>
1.0.0
</version>
</parent>
<artifactId>
springcloud-service-consul
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<name>
springcloud-service-consul
</name>
<properties>
<java.version>
1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>
com.kwan.springcloud
</groupId>
<artifactId>
springcloud-service-common
</artifactId>
<version>
1.0.0
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-consul-discovery
</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
springcloud-service-consul/src/main/java/com/kwan/springcloud/ConsulApplication.java
0 → 100644
浏览文件 @
cf53e5fa
package
com.kwan.springcloud
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
ConsulApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
ConsulApplication
.
class
,
args
);
}
}
springcloud-service-consul/src/main/java/com/kwan/springcloud/controller/ConsulController.java
0 → 100644
浏览文件 @
cf53e5fa
package
com.kwan.springcloud.controller
;
import
com.kwan.springcloud.response.Result
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* portal控制器
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/1/8 11:12
*/
@RestController
@RequestMapping
(
"/consul"
)
public
class
ConsulController
{
@GetMapping
(
value
=
"/test"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
test
()
{
return
Result
.
ok
(
"consul 访问成功"
);
}
}
\ No newline at end of file
springcloud-service-consul/src/main/resources/application.yaml
0 → 100644
浏览文件 @
cf53e5fa
#端口号
server
:
port
:
8500
spring
:
application
:
name
:
consul-service
#服务名称
cloud
:
consul
:
host
:
localhost
port
:
8500
\ No newline at end of file
springcloud-service-consul/src/test/java/com/kwan/springcloud/PortalApplicationTests.java
0 → 100644
浏览文件 @
cf53e5fa
package
com.kwan.springcloud
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
class
PortalApplicationTests
{
@Test
void
contextLoads
()
{
}
}
springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java
浏览文件 @
cf53e5fa
...
...
@@ -13,7 +13,7 @@ import java.io.Serializable;
import
java.util.List
;
@RestController
@RequestMapping
(
"kwanGoodsInfo"
)
@RequestMapping
(
"
/
kwanGoodsInfo"
)
public
class
KwanGoodsInfoController
{
/**
* 服务对象
...
...
springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java
浏览文件 @
cf53e5fa
...
...
@@ -13,7 +13,7 @@ import java.io.Serializable;
import
java.util.List
;
@RestController
@RequestMapping
(
"kwanGoodsInfo"
)
@RequestMapping
(
"
/
kwanGoodsInfo"
)
public
class
KwanGoodsInfoController
{
/**
* 服务对象
...
...
springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java
浏览文件 @
cf53e5fa
...
...
@@ -13,7 +13,7 @@ import java.io.Serializable;
import
java.util.List
;
@RestController
@RequestMapping
(
"kwanGoodsInfo"
)
@RequestMapping
(
"
/
kwanGoodsInfo"
)
public
class
KwanGoodsInfoController
{
/**
* 服务对象
...
...
springcloud-service-portal/src/main/java/com/kwan/springcloud/controller/PortalController.java
浏览文件 @
cf53e5fa
...
...
@@ -34,4 +34,10 @@ public class PortalController {
public
Result
selectOne
(
@PathVariable
String
id
)
{
return
portalService
.
addService
(
id
);
}
@GetMapping
(
value
=
"/test"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
test
()
{
return
Result
.
ok
(
"portal 访问成功"
);
}
}
\ No newline at end of file
springcloud-service-zuul/pom.xml
浏览文件 @
cf53e5fa
...
...
@@ -34,9 +34,8 @@
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-
netflix-eureka-client
</artifactId>
<artifactId>
spring-cloud-starter-
eureka
</artifactId>
</dependency>
</dependencies>
<build>
...
...
springcloud-service-zuul/src/main/java/com/kwan/springcloud/GoodsServiceFallBackProvider.java
已删除
100644 → 0
浏览文件 @
f6fc046e
package
com.kwan.springcloud
;
import
org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.stereotype.Component
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
/**
* FallbackProvider(请求异常处理)
* <p>
* 网关的默认回退FallbackProvider的机制只适用于通过配置文件中配置的url来跨服务调用,而不拦截通过FeignClient跨服务调用,
* 也就是说要自己实现一个FeignClient服务的fallback才可以,但是如果通过FeignClient的服务要是特别多怎么办,每一个都要写一个不得累死,
* 这里想到了通过网关的错误过滤器来统一处理FeignClient跨服务调用出错的问题
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/1/11 12:48
*/
@Component
public
class
GoodsServiceFallBackProvider
implements
FallbackProvider
{
@Override
public
String
getRoute
()
{
return
"goods-service"
;
}
@Override
public
ClientHttpResponse
fallbackResponse
(
String
route
,
Throwable
cause
)
{
return
new
ClientHttpResponse
()
{
@Override
public
HttpHeaders
getHeaders
()
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON_UTF8
);
return
headers
;
}
@Override
public
InputStream
getBody
()
throws
IOException
{
return
new
ByteArrayInputStream
(
"order-service is not available!"
.
getBytes
());
}
@Override
public
HttpStatus
getStatusCode
()
throws
IOException
{
return
HttpStatus
.
BAD_REQUEST
;
}
@Override
public
int
getRawStatusCode
()
throws
IOException
{
return
this
.
getStatusCode
().
value
();
}
@Override
public
String
getStatusText
()
throws
IOException
{
return
this
.
getStatusCode
().
getReasonPhrase
();
}
@Override
public
void
close
()
{
}
};
}
}
springcloud-service-zuul/src/main/java/com/kwan/springcloud/filter/MyZuulFilter.java
已删除
100644 → 0
浏览文件 @
f6fc046e
package
com.kwan.springcloud.filter
;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.context.RequestContext
;
import
com.netflix.zuul.exception.ZuulException
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.http.HttpServletRequest
;
@Component
public
class
MyZuulFilter
extends
ZuulFilter
{
/**
* 表示当前的过滤器是否被调用
*/
@Override
public
boolean
shouldFilter
()
{
return
true
;
}
/**
* filterOrder表示执行的优先级,值越小表示优先级越高
*/
@Override
public
int
filterOrder
()
{
return
0
;
}
/**
* pre: 在请求被路由之前调用
* routing: 在请求被路由之中调用
* post: 在请求被路由之后调用
* error: 处理请求发生错误时调用
*/
@Override
public
String
filterType
()
{
return
"pre"
;
}
/**
* 真正执行Filter逻辑的方法
*/
@Override
public
Object
run
()
throws
ZuulException
{
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
HttpServletRequest
request
=
ctx
.
getRequest
();
System
.
err
.
println
(
"--------------uri: -------------- "
+
request
.
getRequestURI
());
return
ctx
;
}
}
\ No newline at end of file
springcloud-service-zuul/src/main/resources/application.yaml
浏览文件 @
cf53e5fa
...
...
@@ -11,14 +11,28 @@ zuul:
sensitiveHeaders
:
Cookie,Set-Cookie,Authorization
routes
:
api-portal
:
path
:
/portal-service/**
#访问路径:http:/localhost:
5001/hello-service/hello
path
:
/portal-service/**
#访问路径:http:/localhost:
8888/portal-service/portal/1
serviceId
:
portal-service
api-goods
:
path
:
/goods-service/**
serviceld
:
goods-service
url
:
http://localhost:9100/,http://localhost:9200/,http://localhost:9300/
retryable
:
true
semaphore
:
max-semaphores
:
100
ribbon-isolation-strategy
:
thread
# prefix: /api
strip-prefix
:
false
#服务提供者
eureka
:
client
:
service-url
:
defaultZone
:
http://eureka8767:8767/eureka/,http://eureka8768:8768/eureka/,http://eureka8769:8769/eureka/
\ No newline at end of file
defaultZone
:
http://eureka8767:8767/eureka/,http://eureka8768:8768/eureka/,http://eureka8769:8769/eureka/
ribbon
:
ConnectTimeout
:
250
#连接超时时间(ms),默认值为250ms
ReadTimeout
:
2000
#通信超时时间(ms),默认值为2000ms
MaxAutoRetriesNextServer
:
0
#对同一服务不同实例重试次数(同一服务下集群个数的重试次数)
MaxAutoRetries
:
2
#对同一实例重试的次数(单个集群节点服务重试的次数)
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录