Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringCloudAlibaba
提交
adddfe80
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看板
提交
adddfe80
编写于
2月 11, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:feign调用
上级
2f646233
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
30 deletion
+37
-30
nacos-server-common/src/main/java/com/kwan/springcloudalibaba/api/ComputeClient.java
...n/java/com/kwan/springcloudalibaba/api/ComputeClient.java
+4
-3
nacos-server-common/src/main/java/com/kwan/springcloudalibaba/api/ComputeClientHystrix.java
...com/kwan/springcloudalibaba/api/ComputeClientHystrix.java
+19
-19
nacos-server-consumer/src/main/java/com/kwan/springcloudalibaba/controller/ConsumerUserController.java
...springcloudalibaba/controller/ConsumerUserController.java
+5
-3
nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/controller/UserController.java
...om/kwan/springcloudalibaba/controller/UserController.java
+9
-5
未找到文件。
nacos-server-common/src/main/java/com/kwan/springcloudalibaba/api/ComputeClient.java
浏览文件 @
adddfe80
...
...
@@ -14,10 +14,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
* @version : 2.2.0
* @date : 2023/1/10 13:45
*/
@FeignClient
(
value
=
"nacos-server-producer/user"
,
fallback
=
ComputeClientHystrix
.
class
)
//@FeignClient(value = "nacos-server-producer",path = "/user", fallback = ComputeClientHystrix.class)
@FeignClient
(
value
=
"nacos-server-producer"
,
path
=
"/user"
)
public
interface
ComputeClient
{
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
Result
getUserById
(
@PathVariable
Integer
id
);
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"
/
{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
Result
selectOne
(
@PathVariable
Integer
id
);
}
nacos-server-common/src/main/java/com/kwan/springcloudalibaba/api/ComputeClientHystrix.java
浏览文件 @
adddfe80
package
com.kwan.springcloudalibaba.api
;
import
com.kwan.springcloudalibaba.common.Result
;
import
org.springframework.stereotype.Component
;
/**
* feign的降级
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/1/14 16:47
*/
@Component
public
class
ComputeClientHystrix
implements
ComputeClient
{
@Override
public
Result
getUserById
(
Integer
id
)
{
return
Result
.
error
(
"feign方式请求 服务不可用 请求失败"
);
}
}
//
package com.kwan.springcloudalibaba.api;
//
//
import com.kwan.springcloudalibaba.common.Result;
//
import org.springframework.stereotype.Component;
//
/
//
**
//
* feign的降级
//
*
//
* @author : qinyingjie
//
* @version : 2.2.0
//
* @date : 2023/1/14 16:47
//
*/
//
@Component
//
public class ComputeClientHystrix implements ComputeClient {
//
@Override
// public Result selectOne
(Integer id) {
//
return Result.error("feign方式请求 服务不可用 请求失败");
//
}
//
}
nacos-server-consumer/src/main/java/com/kwan/springcloudalibaba/controller/ConsumerUserController.java
浏览文件 @
adddfe80
...
...
@@ -21,14 +21,16 @@ public class ConsumerUserController {
/**
* http://127.0.0.1:8085/nacos/consumer/getUserById/1
* http://127.0.0.1:8085/nacos/consumer/1
* <p>
* http://localhost:9091/user/1
*
* @param id
* @return
*/
@GetMapping
(
value
=
"/
getUserById/
{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
@GetMapping
(
value
=
"/{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
getUserById
(
@PathVariable
Integer
id
)
{
return
Result
.
ok
(
computeClient
.
getUserById
(
id
));
return
Result
.
ok
(
computeClient
.
selectOne
(
id
));
}
/**
...
...
nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/controller/UserController.java
浏览文件 @
adddfe80
...
...
@@ -6,6 +6,7 @@ import com.kwan.springcloudalibaba.entity.User;
import
com.kwan.springcloudalibaba.service.IUserService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
...
...
@@ -26,16 +27,19 @@ public class UserController {
private
IUserService
userService
;
/**
*
http://127.0.0.1:9091/user/getUserById/1
*
通过主键查询单条数据
*
* @param id
* @return
* http://localhost:9091/user/1
*
* @param id 主键
* @return 单条数据
*/
@
RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
public
Result
getUserById
(
@PathVariable
Integer
id
)
{
@
GetMapping
(
value
=
"/{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
selectOne
(
@PathVariable
Integer
id
)
{
return
Result
.
ok
(
userService
.
getUserById
(
id
));
}
@RequestMapping
(
value
=
"/all"
,
method
=
RequestMethod
.
GET
)
public
List
<
User
>
addAdvertise
()
{
log
.
info
(
"测试日志={}"
,
"success"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录