Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
SpringCloudServerConsumer
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiachenqi
SpringCloudServerConsumer
Commits
7fff2afe
Commit
7fff2afe
authored
Jul 04, 2019
by
XCQi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
远程服务调用现已支持负载均衡 默认情况下轮询方式负载
支持断路和降级 不可用的实例将暂时被踢出可用列表 全部实例不可用的时候将降级响应预设内容
parent
0793034b
Pipeline
#47
failed with stages
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
3 deletions
+91
-3
RestApi.java
...a/com/yingxin/springcloudconsumer/controller/RestApi.java
+13
-0
User.java
...ain/java/com/yingxin/springcloudconsumer/entity/User.java
+41
-0
HelloFallBack.java
...om/yingxin/springcloudconsumer/service/HelloFallBack.java
+24
-0
HelloService.java
...com/yingxin/springcloudconsumer/service/HelloService.java
+10
-1
application.properties
src/main/resources/application.properties
+3
-2
No files found.
src/main/java/com/yingxin/springcloudconsumer/controller/RestApi.java
View file @
7fff2afe
package
com
.
yingxin
.
springcloudconsumer
.
controller
;
package
com
.
yingxin
.
springcloudconsumer
.
controller
;
import
com.yingxin.springcloudconsumer.entity.User
;
import
com.yingxin.springcloudconsumer.service.HelloService
;
import
com.yingxin.springcloudconsumer.service.HelloService
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@RestController
@RestController
public
class
RestApi
{
public
class
RestApi
{
...
@@ -17,4 +20,14 @@ public class RestApi {
...
@@ -17,4 +20,14 @@ public class RestApi {
public
String
helloConsumer
()
{
public
String
helloConsumer
()
{
return
helloService
.
hello
();
return
helloService
.
hello
();
}
}
@GetMapping
(
"user"
)
public
User
userConsumer
()
{
return
helloService
.
getUser
();
}
@GetMapping
(
"users"
)
public
List
<
User
>
usersConsumer
()
{
return
helloService
.
getUsers
();
}
}
}
src/main/java/com/yingxin/springcloudconsumer/entity/User.java
0 → 100644
View file @
7fff2afe
package
com
.
yingxin
.
springcloudconsumer
.
entity
;
public
class
User
{
private
String
id
;
private
String
name
;
//姓名
private
Integer
age
;
//年龄
public
User
()
{
}
public
User
(
String
id
,
String
name
,
Integer
age
)
{
this
.
id
=
id
;
this
.
name
=
name
;
this
.
age
=
age
;
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
Integer
getAge
()
{
return
age
;
}
public
void
setAge
(
Integer
age
)
{
this
.
age
=
age
;
}
}
src/main/java/com/yingxin/springcloudconsumer/service/HelloFallBack.java
0 → 100644
View file @
7fff2afe
package
com
.
yingxin
.
springcloudconsumer
.
service
;
import
com.yingxin.springcloudconsumer.entity.User
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
@Component
public
class
HelloFallBack
implements
HelloService
{
@Override
public
String
hello
()
{
return
"service error"
;
}
@Override
public
User
getUser
()
{
return
new
User
();
}
@Override
public
List
<
User
>
getUsers
()
{
return
null
;
}
}
src/main/java/com/yingxin/springcloudconsumer/service/HelloService.java
View file @
7fff2afe
package
com
.
yingxin
.
springcloudconsumer
.
service
;
package
com
.
yingxin
.
springcloudconsumer
.
service
;
import
com.yingxin.springcloudconsumer.entity.User
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
@FeignClient
(
"spring-cloud-server-HelloWorld"
)
import
java.util.List
;
@FeignClient
(
name
=
"spring-cloud-server-HelloWorld"
,
fallback
=
HelloFallBack
.
class
)
public
interface
HelloService
{
public
interface
HelloService
{
@GetMapping
(
"hello"
)
@GetMapping
(
"hello"
)
String
hello
();
String
hello
();
@GetMapping
(
"exampleforget"
)
User
getUser
();
@GetMapping
(
"queryUserList"
)
List
<
User
>
getUsers
();
}
}
src/main/resources/application.properties
View file @
7fff2afe
server.port
=
9000
server.port
=
9000
spring.application.name
=
consumer
spring.application.name
=
consumer
eureka.client.service-url.defaultZone
=
http://localhost:8761/eureka/
eureka.client.service-url.defaultZone
=
http://localhost:8761/eureka/
\ No newline at end of file
feign.hystrix.enabled
=
true
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment