Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringCloudAlibaba
提交
2f646233
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看板
提交
2f646233
编写于
2月 11, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:添加feign,未成功调用,还得参考之前的项目
上级
f3c2e916
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
113 addition
and
22 deletion
+113
-22
nacos-server-common/pom.xml
nacos-server-common/pom.xml
+24
-0
nacos-server-common/src/main/java/com/kwan/springcloudalibaba/api/ComputeClient.java
...n/java/com/kwan/springcloudalibaba/api/ComputeClient.java
+23
-0
nacos-server-common/src/main/java/com/kwan/springcloudalibaba/api/ComputeClientHystrix.java
...com/kwan/springcloudalibaba/api/ComputeClientHystrix.java
+19
-0
nacos-server-consumer/pom.xml
nacos-server-consumer/pom.xml
+1
-0
nacos-server-consumer/src/main/java/com/kwan/springcloudalibaba/NacosConsumerApplication.java
...com/kwan/springcloudalibaba/NacosConsumerApplication.java
+4
-10
nacos-server-consumer/src/main/java/com/kwan/springcloudalibaba/controller/ConsumerUserController.java
...springcloudalibaba/controller/ConsumerUserController.java
+18
-5
nacos-server-producer/pom.xml
nacos-server-producer/pom.xml
+12
-0
nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/controller/UserController.java
...om/kwan/springcloudalibaba/controller/UserController.java
+12
-7
未找到文件。
nacos-server-common/pom.xml
浏览文件 @
2f646233
...
...
@@ -13,11 +13,35 @@
<description>
nacos-server-common
</description>
<version>
1.0.0
</version>
<properties>
<java.version>
1.8
</java.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
<spring-boot.version>
2.3.0.RELEASE
</spring-boot.version>
<spring-cloud-alibaba.version>
2.2.1.RELEASE
</spring-cloud-alibaba.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</dependency>
<dependency>
<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>-->
</dependencies>
</project>
\ No newline at end of file
nacos-server-common/src/main/java/com/kwan/springcloudalibaba/api/ComputeClient.java
0 → 100644
浏览文件 @
2f646233
package
com.kwan.springcloudalibaba.api
;
import
com.kwan.springcloudalibaba.common.Result
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
/**
* 使用feign配置goods-service服务
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/1/10 13:45
*/
@FeignClient
(
value
=
"nacos-server-producer/user"
,
fallback
=
ComputeClientHystrix
.
class
)
public
interface
ComputeClient
{
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
Result
getUserById
(
@PathVariable
Integer
id
);
}
nacos-server-common/src/main/java/com/kwan/springcloudalibaba/api/ComputeClientHystrix.java
0 → 100644
浏览文件 @
2f646233
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方式请求 服务不可用 请求失败"
);
}
}
nacos-server-consumer/pom.xml
浏览文件 @
2f646233
...
...
@@ -20,6 +20,7 @@
<spring-boot.version>
2.3.0.RELEASE
</spring-boot.version>
<spring-cloud-alibaba.version>
2.2.1.RELEASE
</spring-cloud-alibaba.version>
</properties>
<dependencies>
<dependency>
<groupId>
com.kwan.springcloudalibaba
</groupId>
...
...
nacos-server-consumer/src/main/java/com/kwan/springcloudalibaba/NacosConsumerApplication.java
浏览文件 @
2f646233
...
...
@@ -4,17 +4,11 @@ import org.springframework.boot.SpringApplication;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
/**
* http://localhost:8085/nacos/consumer/nameInfo
* <p>
* <p>
* 消费者
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/1/17 12:37
*/
//@EnableFeignClients
//@EnableCircuitBreaker
@SpringBootApplication
//@SpringBootApplication(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public
class
NacosConsumerApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
nacos-server-consumer/src/main/java/com/kwan/springcloudalibaba/controller/
NacosConsum
erController.java
→
nacos-server-consumer/src/main/java/com/kwan/springcloudalibaba/controller/
ConsumerUs
erController.java
浏览文件 @
2f646233
package
com.kwan.springcloudalibaba.controller
;
import
com.kwan.springcloudalibaba.api.ComputeClient
;
import
com.kwan.springcloudalibaba.common.Result
;
import
org.springframework.beans.factory.annotation.
Value
;
import
org.springframework.beans.factory.annotation.
Autowired
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
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
;
...
...
@@ -12,18 +14,29 @@ import org.springframework.web.bind.annotation.RestController;
@RefreshScope
@RestController
@RequestMapping
(
"/nacos/consumer"
)
public
class
NacosConsum
erController
{
public
class
ConsumerUs
erController
{
@
Value
(
"${user.name}"
)
private
String
nameInfo
;
@
Autowired
private
ComputeClient
computeClient
;
/**
* http://127.0.0.1:8085/nacos/consumer/getUserById/1
*
* @param id
* @return
*/
@GetMapping
(
value
=
"/getUserById/{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
getUserById
(
@PathVariable
Integer
id
)
{
return
Result
.
ok
(
computeClient
.
getUserById
(
id
));
}
/**
* 获取配置的变量
*/
@GetMapping
(
value
=
"/nameInfo"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
nameInfo
()
{
return
Result
.
ok
(
nameInfo
);
return
Result
.
ok
();
}
}
...
...
nacos-server-producer/pom.xml
浏览文件 @
2f646233
...
...
@@ -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>
...
...
nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/controller/UserController.java
浏览文件 @
2f646233
package
com.kwan.springcloudalibaba.controller
;
import
com.kwan.springcloudalibaba.common.Result
;
import
com.kwan.springcloudalibaba.entity.User
;
import
com.kwan.springcloudalibaba.service.IUserService
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -24,19 +25,23 @@ public class UserController {
@Autowired
private
IUserService
userService
;
/**
* http://127.0.0.1:9091/user/getUserById/1
*
* @param id
* @return
*/
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
public
Result
getUserById
(
@PathVariable
Integer
id
)
{
return
Result
.
ok
(
userService
.
getUserById
(
id
));
}
@RequestMapping
(
value
=
"/all"
,
method
=
RequestMethod
.
GET
)
public
List
<
User
>
addAdvertise
()
{
log
.
info
(
"测试日志={}"
,
"success"
);
return
userService
.
getUsers
();
}
@RequestMapping
(
value
=
"/getUserById/{id}"
,
method
=
RequestMethod
.
GET
)
public
User
getUserById
(
@PathVariable
Integer
id
)
{
return
userService
.
getUserById
(
id
);
}
@RequestMapping
(
value
=
"/getUserByName"
,
method
=
RequestMethod
.
GET
)
public
User
getUserByName
(
@RequestParam
String
sex
)
{
return
userService
.
getUserByName
(
sex
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录