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
d2b74e04
Commit
d2b74e04
authored
Jul 10, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
控制台增加批量异步推送规则配置信息接口
parent
045d44d4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
6 deletions
+57
-6
discovery-console/pom.xml
+5
-0
discovery-console/src/main/java/com/nepxion/discovery/console/configuration/ConsoleAutoConfiguration.java
+6
-1
discovery-console/src/main/java/com/nepxion/discovery/console/endpoint/ConsoleEndpoint.java
+13
-5
discovery-console/src/main/java/com/nepxion/discovery/console/handler/ConsoleErrorHandler.java
+33
-0
No files found.
discovery-console/pom.xml
View file @
d2b74e04
...
...
@@ -21,6 +21,11 @@
</dependency>
<dependency>
<groupId>
commons-io
</groupId>
<artifactId>
commons-io
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter
</artifactId>
</dependency>
...
...
discovery-console/src/main/java/com/nepxion/discovery/console/configuration/ConsoleAutoConfiguration.java
View file @
d2b74e04
...
...
@@ -17,6 +17,7 @@ import org.springframework.context.annotation.Import;
import
org.springframework.web.client.RestTemplate
;
import
com.nepxion.discovery.console.endpoint.ConsoleEndpoint
;
import
com.nepxion.discovery.console.handler.ConsoleErrorHandler
;
@Configuration
// @ComponentScan(basePackages = { "com.nepxion.discovery.console.endpoint" })
...
...
@@ -45,7 +46,10 @@ public class ConsoleAutoConfiguration {
@Bean
public
RestTemplate
consoleRestTemplate
()
{
return
new
RestTemplate
();
RestTemplate
restTemplate
=
new
RestTemplate
();
restTemplate
.
setErrorHandler
(
new
ConsoleErrorHandler
());
return
restTemplate
;
}
}
}
\ No newline at end of file
discovery-console/src/main/java/com/nepxion/discovery/console/endpoint/ConsoleEndpoint.java
View file @
d2b74e04
...
...
@@ -38,6 +38,7 @@ import org.springframework.web.bind.annotation.RestController;
import
org.springframework.web.client.RestTemplate
;
import
com.nepxion.discovery.console.entity.InstanceEntity
;
import
com.nepxion.discovery.console.handler.ConsoleErrorHandler
;
@RestController
@Api
(
tags
=
{
"控制台接口"
})
...
...
@@ -140,6 +141,8 @@ public class ConsoleEndpoint implements MvcEndpoint {
}
private
ResponseEntity
<?>
send
(
String
serviceId
,
String
config
,
boolean
async
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
List
<
ServiceInstance
>
serviceInstances
=
getInstances
(
serviceId
);
for
(
ServiceInstance
serviceInstance
:
serviceInstances
)
{
String
host
=
serviceInstance
.
getHost
();
...
...
@@ -148,15 +151,20 @@ public class ConsoleEndpoint implements MvcEndpoint {
String
url
=
"http://"
+
host
+
":"
+
port
+
"/config/send-"
+
(
async
?
"async"
:
"sync"
);
String
result
=
consoleRestTemplate
.
postForEntity
(
url
,
config
,
String
.
class
).
getBody
();
LOG
.
info
(
"Send rule, serviceId={} url={}, result={}"
,
serviceId
,
url
,
result
);
// 这里需要考虑分布式事务
// 这里最好考虑分布式事务
if
(!
StringUtils
.
equals
(
result
,
"OK"
))
{
return
ResponseEntity
.
ok
().
body
(
"Send rule failed for url="
+
url
+
", cause="
+
result
);
ConsoleErrorHandler
errorHandler
=
(
ConsoleErrorHandler
)
consoleRestTemplate
.
getErrorHandler
();
result
=
errorHandler
.
getCause
();
}
stringBuilder
.
append
(
"Rule sent, serviceId="
).
append
(
serviceId
).
append
(
", url="
).
append
(
url
).
append
(
", result="
).
append
(
result
).
append
(
"\n"
);
}
return
ResponseEntity
.
ok
().
body
(
"OK"
);
String
result
=
stringBuilder
.
toString
();
result
=
result
.
substring
(
0
,
result
.
lastIndexOf
(
"\n"
));
LOG
.
info
(
"\n{}"
,
result
);
return
ResponseEntity
.
ok
().
body
(
result
);
}
@Override
...
...
discovery-console/src/main/java/com/nepxion/discovery/console/handler/ConsoleErrorHandler.java
0 → 100644
View file @
d2b74e04
package
com
.
nepxion
.
discovery
.
console
.
handler
;
/**
* <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
java.io.IOException
;
import
java.io.InputStream
;
import
org.apache.commons.io.IOUtils
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.web.client.DefaultResponseErrorHandler
;
public
class
ConsoleErrorHandler
extends
DefaultResponseErrorHandler
{
private
String
cause
;
@Override
public
void
handleError
(
ClientHttpResponse
response
)
throws
IOException
{
// 这里绝对不能关闭InputStream
InputStream
inputStream
=
response
.
getBody
();
cause
=
IOUtils
.
toString
(
inputStream
,
"UTF-8"
);
}
public
String
getCause
()
{
return
cause
;
}
}
\ 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