Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢捷峰
discovery
Commits
15afbe28
Commit
15afbe28
authored
Aug 31, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加RestTemplateStrategyInterceptor机制
parent
c0517136
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
163 additions
and
0 deletions
+163
-0
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/DiscoveryApplicationA1.java
+14
-0
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/rest/ARestImpl.java
+42
-0
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/rest/AbstractRestImpl.java
+29
-0
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/rest/BRestImpl.java
+42
-0
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/rest/CRestImpl.java
+36
-0
No files found.
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/DiscoveryApplicationA1.java
View file @
15afbe28
...
@@ -9,17 +9,22 @@ package com.nepxion.discovery.plugin.example.service;
...
@@ -9,17 +9,22 @@ package com.nepxion.discovery.plugin.example.service;
* @version 1.0
* @version 1.0
*/
*/
import
java.util.Collections
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.client.loadbalancer.LoadBalanced
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.web.client.RestTemplate
;
import
com.nepxion.discovery.plugin.example.service.impl.MyDiscoveryEnabledStrategy
;
import
com.nepxion.discovery.plugin.example.service.impl.MyDiscoveryEnabledStrategy
;
import
com.nepxion.discovery.plugin.example.service.impl.MyDiscoveryListener
;
import
com.nepxion.discovery.plugin.example.service.impl.MyDiscoveryListener
;
import
com.nepxion.discovery.plugin.example.service.impl.MyLoadBalanceListener
;
import
com.nepxion.discovery.plugin.example.service.impl.MyLoadBalanceListener
;
import
com.nepxion.discovery.plugin.example.service.impl.MyRegisterListener
;
import
com.nepxion.discovery.plugin.example.service.impl.MyRegisterListener
;
import
com.nepxion.discovery.plugin.example.service.impl.MySubscriber
;
import
com.nepxion.discovery.plugin.example.service.impl.MySubscriber
;
import
com.nepxion.discovery.plugin.strategy.service.aop.RestTemplateStrategyInterceptor
;
@SpringBootApplication
@SpringBootApplication
@EnableDiscoveryClient
@EnableDiscoveryClient
...
@@ -32,6 +37,15 @@ public class DiscoveryApplicationA1 {
...
@@ -32,6 +37,15 @@ public class DiscoveryApplicationA1 {
}
}
@Bean
@Bean
@LoadBalanced
public
RestTemplate
restTemplate
(
RestTemplateStrategyInterceptor
restTemplateStrategyInterceptor
)
{
RestTemplate
restTemplate
=
new
RestTemplate
();
restTemplate
.
setInterceptors
(
Collections
.
singletonList
(
restTemplateStrategyInterceptor
));
return
restTemplate
;
}
@Bean
public
MyRegisterListener
myRegisterListener
()
{
public
MyRegisterListener
myRegisterListener
()
{
return
new
MyRegisterListener
();
return
new
MyRegisterListener
();
}
}
...
...
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/rest/ARestImpl.java
0 → 100644
View file @
15afbe28
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
service
.
rest
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.client.RestTemplate
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
@RestController
@ConditionalOnProperty
(
name
=
DiscoveryConstant
.
SPRING_APPLICATION_NAME
,
havingValue
=
"discovery-springcloud-example-a"
)
public
class
ARestImpl
extends
AbstractRestImpl
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ARestImpl
.
class
);
@Autowired
private
RestTemplate
restTemplate
;
@RequestMapping
(
path
=
"/rest"
,
method
=
RequestMethod
.
POST
)
public
String
rest
(
@RequestBody
String
value
)
{
value
=
doRest
(
value
);
value
=
restTemplate
.
postForEntity
(
"http://discovery-springcloud-example-b/rest"
,
value
,
String
.
class
).
getBody
();
LOG
.
info
(
"调用路径:{}"
,
value
);
return
value
;
}
}
\ No newline at end of file
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/rest/AbstractRestImpl.java
0 → 100644
View file @
15afbe28
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
service
.
rest
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
public
class
AbstractRestImpl
{
@Autowired
private
PluginAdapter
pluginAdapter
;
public
String
doRest
(
String
value
)
{
String
serviceId
=
pluginAdapter
.
getServiceId
();
String
version
=
pluginAdapter
.
getVersion
();
// String host = pluginAdapter.getHost();
// int port = pluginAdapter.getPort();
return
value
+
" -> "
+
serviceId
+
"["
+
version
+
"]"
;
}
}
\ No newline at end of file
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/rest/BRestImpl.java
0 → 100644
View file @
15afbe28
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
service
.
rest
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.client.RestTemplate
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
@RestController
@ConditionalOnProperty
(
name
=
DiscoveryConstant
.
SPRING_APPLICATION_NAME
,
havingValue
=
"discovery-springcloud-example-b"
)
public
class
BRestImpl
extends
AbstractRestImpl
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
BRestImpl
.
class
);
@Autowired
private
RestTemplate
restTemplate
;
@RequestMapping
(
path
=
"/rest"
,
method
=
RequestMethod
.
POST
)
public
String
rest
(
@RequestBody
String
value
)
{
value
=
doRest
(
value
);
value
=
restTemplate
.
postForEntity
(
"http://discovery-springcloud-example-c/rest"
,
value
,
String
.
class
).
getBody
();
LOG
.
info
(
"调用路径:{}"
,
value
);
return
value
;
}
}
\ No newline at end of file
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/rest/CRestImpl.java
0 → 100644
View file @
15afbe28
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
service
.
rest
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
@RestController
@ConditionalOnProperty
(
name
=
DiscoveryConstant
.
SPRING_APPLICATION_NAME
,
havingValue
=
"discovery-springcloud-example-c"
)
public
class
CRestImpl
extends
AbstractRestImpl
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
CRestImpl
.
class
);
@RequestMapping
(
path
=
"/rest"
,
method
=
RequestMethod
.
POST
)
public
String
rest
(
@RequestBody
String
value
)
{
value
=
doRest
(
value
);
LOG
.
info
(
"调用路径:{}"
,
value
);
return
value
;
}
}
\ 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