Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
commons
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
commons
Commits
74376088
Commit
74376088
authored
Dec 19, 2017
by
朱劲松
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. customize Endpoint for health check.
2. 修改pom.xml,集成必要的spring-cloud依赖
parent
6297abcc
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
327 additions
and
21 deletions
+327
-21
pom.xml
pom.xml
+115
-15
EndpointAutoConfiguration.java
...ntgroup/tech/autoconfigure/EndpointAutoConfiguration.java
+24
-0
ServiceUrls.java
src/main/java/cn/quantgroup/tech/constant/ServiceUrls.java
+0
-6
HealthCheckEndpoint.java
...java/cn/quantgroup/tech/endpoint/HealthCheckEndpoint.java
+22
-0
DefaultSignalHandler.java
...ava/cn/quantgroup/tech/shutdown/DefaultSignalHandler.java
+1
-0
Result.java
src/main/java/cn/quantgroup/tech/web/dto/Result.java
+101
-0
ResultStatus.java
src/main/java/cn/quantgroup/tech/web/dto/ResultStatus.java
+62
-0
spring.factories
src/main/resources/META-INF/spring.factories
+2
-0
No files found.
pom.xml
View file @
74376088
...
@@ -13,19 +13,129 @@
...
@@ -13,19 +13,129 @@
<properties>
<properties>
<java.version>
1.8
</java.version>
<java.version>
1.8
</java.version>
<guava.version>
23.0
</guava.version>
<guava.version>
23.0
</guava.version>
<apollo.client.version>
0.
9.2
</apollo.client.version>
<apollo.client.version>
0.
10.0
</apollo.client.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
<maven.test.skip>
true
</maven.test.skip>
</properties>
</properties>
<parent>
<parent>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
1.5.
6
.RELEASE
</version>
<version>
1.5.
8
.RELEASE
</version>
</parent>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
1.5.8.RELEASE
</version>
<scope>
import
</scope>
<type>
pom
</type>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-dependencies
</artifactId>
<version>
Dalston.SR4
</version>
<scope>
import
</scope>
<type>
pom
</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
<scope>
compile
</scope>
<exclusions>
<exclusion>
<artifactId>
spring-boot-starter-tomcat
</artifactId>
<groupId>
*
</groupId>
</exclusion>
<exclusion>
<artifactId>
jboss-servlet-api_3.1_spec
</artifactId>
<groupId>
org.jboss.spec.javax.servlet
</groupId>
</exclusion>
<exclusion>
<artifactId>
commons-logging
</artifactId>
<groupId>
commons-logging
</groupId>
</exclusion>
<exclusion>
<artifactId>
annotations
</artifactId>
<groupId>
com.google.code.findbugs
</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-undertow
</artifactId>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
<scope>
compile
</scope>
</dependency>
<!--<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
<scope>compile</scope>
</dependency>-->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.41
</version>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-sleuth-zipkin-stream
</artifactId>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-stream-kafka
</artifactId>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.6
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-annotations
</artifactId>
<version>
2.8.8
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-databind
</artifactId>
<version>
2.8.8
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
...
@@ -48,24 +158,14 @@
...
@@ -48,24 +158,14 @@
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-tomcat
</artifactId>
<artifactId>
spring-boot-starter-amqp
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-undertow
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-jetty
</artifactId>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-
amqp
</artifactId>
<artifactId>
spring-boot-starter-
test
</artifactId>
<
optional>
true
</optional
>
<
scope>
test
</scope
>
</dependency>
</dependency>
</dependencies>
</dependencies>
...
...
src/main/java/cn/quantgroup/tech/autoconfigure/EndpointAutoConfiguration.java
0 → 100644
View file @
74376088
package
cn
.
quantgroup
.
tech
.
autoconfigure
;
import
cn.quantgroup.tech.endpoint.HealthCheckEndpoint
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration
;
import
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author jinsong.zhu
* @date 2017/12/18
*/
@Configuration
@AutoConfigureAfter
({
FlywayAutoConfiguration
.
class
,
LiquibaseAutoConfiguration
.
class
})
public
class
EndpointAutoConfiguration
{
@Bean
@ConditionalOnMissingBean
public
HealthCheckEndpoint
environmentEndpoint
()
{
return
new
HealthCheckEndpoint
();
}
}
\ No newline at end of file
src/main/java/cn/quantgroup/tech/constant/ServiceUrls.java
deleted
100644 → 0
View file @
6297abcc
package
cn
.
quantgroup
.
tech
.
constant
;
@Deprecated
public
enum
ServiceUrls
{
}
src/main/java/cn/quantgroup/tech/endpoint/HealthCheckEndpoint.java
0 → 100644
View file @
74376088
package
cn
.
quantgroup
.
tech
.
endpoint
;
import
cn.quantgroup.tech.web.dto.Result
;
import
org.springframework.boot.actuate.endpoint.AbstractEndpoint
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* @author jinsong.zhu
* @date 2017/12/18
*/
@ConfigurationProperties
(
prefix
=
"endpoints.qg.health"
)
public
class
HealthCheckEndpoint
extends
AbstractEndpoint
<
Result
>
{
public
HealthCheckEndpoint
()
{
super
(
"qg-health"
,
false
,
true
);
}
@Override
public
Result
invoke
()
{
return
Result
.
ok
();
}
}
src/main/java/cn/quantgroup/tech/shutdown/DefaultSignalHandler.java
View file @
74376088
...
@@ -4,6 +4,7 @@ import cn.quantgroup.tech.shutdown.properties.GracefulShutdownProperties;
...
@@ -4,6 +4,7 @@ import cn.quantgroup.tech.shutdown.properties.GracefulShutdownProperties;
import
cn.quantgroup.tech.shutdown.service.Shutdown
;
import
cn.quantgroup.tech.shutdown.service.Shutdown
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
sun.misc.Signal
;
import
sun.misc.Signal
;
import
sun.misc.SignalHandler
;
import
sun.misc.SignalHandler
;
...
...
src/main/java/cn/quantgroup/tech/web/dto/Result.java
0 → 100644
View file @
74376088
package
cn
.
quantgroup
.
tech
.
web
.
dto
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* @author zero-mac
* @date 16/6/28
*/
@Getter
@Setter
public
class
Result
{
/**
* 返回码
*/
private
int
code
;
/**
* 返回结果描述
*/
private
String
message
;
/**
* 返回内容
*/
private
Object
data
;
public
int
getCode
()
{
return
code
;
}
public
String
getMessage
()
{
return
message
;
}
public
Object
getData
()
{
return
data
;
}
public
Result
()
{
this
(
ResultStatus
.
INIT
);
}
public
Result
(
int
code
,
String
message
)
{
this
.
code
=
code
;
this
.
message
=
message
;
this
.
data
=
""
;
}
public
Result
(
int
code
,
String
message
,
Object
data
)
{
this
.
code
=
code
;
this
.
message
=
message
;
this
.
data
=
data
;
}
public
Result
(
ResultStatus
status
)
{
this
.
code
=
status
.
getCode
();
this
.
message
=
status
.
getMessage
();
this
.
data
=
null
;
}
public
Result
(
ResultStatus
status
,
Object
data
)
{
this
.
code
=
status
.
getCode
();
this
.
message
=
status
.
getMessage
();
this
.
data
=
data
;
}
public
static
Result
ok
(
Object
data
)
{
return
data
(
data
);
}
public
static
Result
data
(
Object
data
)
{
return
new
Result
(
ResultStatus
.
SUCCESS
,
data
);
}
public
static
Result
ok
()
{
return
new
Result
(
ResultStatus
.
SUCCESS
);
}
public
static
Result
todo
()
{
return
error
(
"TODO"
);
}
public
static
Result
error
(
ResultStatus
error
)
{
return
new
Result
(
error
);
}
public
static
Result
error
(
String
msg
)
{
return
new
Result
(
ResultStatus
.
SERVER_ERROR
.
getCode
(),
msg
);
}
// error状态下不会返回data
public
static
Result
error
(
ResultStatus
error
,
String
msg
)
{
if
(
msg
==
null
)
{
msg
=
error
.
getMessage
();
}
return
new
Result
(
error
.
getCode
(),
msg
,
null
);
}
}
src/main/java/cn/quantgroup/tech/web/dto/ResultStatus.java
0 → 100644
View file @
74376088
package
cn
.
quantgroup
.
tech
.
web
.
dto
;
/**
* 自定义请求状态码
*
* @author zero-mac
* @date 16/6/17
*/
public
enum
ResultStatus
{
INIT
(
0
,
""
),
SUCCESS
(
200
,
""
),
FEIGN_REQUEST_FAILED
(
404
,
"服务端未响应."
),
REQUEST_VALIDATE_ERROR
(
400
,
"请求无效(Bad request),参数异常"
),
// 由开发人员出现严重bug造成的异常
SERVER_ERROR
(
500
,
"开发状态--严重异常,程序无法正常运行,请开发人员检查问题"
),
// 由开发人员代码不严谨造成的异常, 如未进行判空处理等,导致未能返回贴合业务的提示信息
RUNTIME_SERVER_ERROR
(
502
,
"运行状态--异常通知,请开发人员检查问题并作出正确提示"
),
// 数据处理异常提醒, 包括传入数据不正确等, 异常由框架发起
FRAME_SERVER_ERROR
(
504
,
"运行状态--异常通知,请框架维护人员检查问题并作出正确提示"
),
// 数据处理异常提醒, 包括传入数据不正确等, 异常由开发人员发起
APPLICATION_SERVER_ERROR
(
506
,
"运行状态--异常通知,请开发人员检查问题并作出正确提示"
),
//
;
/**
* 返回码
*/
private
int
code
;
/**
* 返回结果描述
*/
private
String
message
;
ResultStatus
(
int
code
,
String
message
)
{
this
.
code
=
code
;
this
.
message
=
message
;
}
public
int
getCode
()
{
return
code
;
}
public
void
setCode
(
int
code
)
{
this
.
code
=
code
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
}
src/main/resources/META-INF/spring.factories
0 → 100644
View file @
74376088
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.quantgroup.tech.autoconfigure.EndpointAutoConfiguration
\ 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