Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
smart_gov_platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
smart_gov_platform
Commits
219a9283
Commit
219a9283
authored
Aug 18, 2022
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改网关日志
parent
73410c40
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
227 additions
and
11 deletions
+227
-11
base-manager/src/main/java/com/mortals/xhx/module/skin/service/impl/SkinTemplateServiceImpl.java
...xhx/module/skin/service/impl/SkinTemplateServiceImpl.java
+5
-0
base-manager/src/test/java/com/mortals/httpclient/site/SiteController.http
...test/java/com/mortals/httpclient/site/SiteController.http
+2
-1
base-manager/src/test/java/com/mortals/httpclient/skin/SkinFieldController.http
...java/com/mortals/httpclient/skin/SkinFieldController.http
+2
-2
base-manager/src/test/java/com/mortals/httpclient/system/system.http
...r/src/test/java/com/mortals/httpclient/system/system.http
+2
-2
smart-gateway/pom.xml
smart-gateway/pom.xml
+13
-3
smart-gateway/src/main/java/com/mortals/xhx/base/framework/config/RabbitConfig.java
...a/com/mortals/xhx/base/framework/config/RabbitConfig.java
+123
-0
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/GlobalCacheRequestFilter.java
...s/xhx/base/framework/filter/GlobalCacheRequestFilter.java
+4
-1
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/GlobalLogFilter.java
...om/mortals/xhx/base/framework/filter/GlobalLogFilter.java
+39
-2
smart-gateway/src/main/java/com/mortals/xhx/common/key/QueueKey.java
...ay/src/main/java/com/mortals/xhx/common/key/QueueKey.java
+25
-0
smart-gateway/src/main/resources/bootstrap.yml
smart-gateway/src/main/resources/bootstrap.yml
+12
-0
No files found.
base-manager/src/main/java/com/mortals/xhx/module/skin/service/impl/SkinTemplateServiceImpl.java
View file @
219a9283
package
com.mortals.xhx.module.skin.service.impl
;
package
com.mortals.xhx.module.skin.service.impl
;
import
cn.hutool.core.exceptions.ExceptionUtil
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.model.PageInfo
;
import
com.mortals.framework.model.PageInfo
;
...
@@ -69,4 +70,8 @@ public class SkinTemplateServiceImpl extends AbstractCRUDServiceImpl<SkinTemplat
...
@@ -69,4 +70,8 @@ public class SkinTemplateServiceImpl extends AbstractCRUDServiceImpl<SkinTemplat
skinFieldService
.
save
(
entity
.
getSkinFieldList
(),
context
);
skinFieldService
.
save
(
entity
.
getSkinFieldList
(),
context
);
}
}
}
}
public
static
void
main
(
String
[]
args
)
{
}
}
}
\ No newline at end of file
base-manager/src/test/java/com/mortals/httpclient/site/SiteController.http
View file @
219a9283
...
@@ -65,7 +65,8 @@ Accept: application/json
...
@@ -65,7 +65,8 @@ Accept: application/json
###构建站点树
###构建站点树
GET {{baseUrl}}/site/siteTree
GET {{baseUrl}}/site/siteTree
Authorization: {{authToken}}
#Authorization: {{authToken}}
Authorization: eyJhbGciOiJIUzI1NiJ9.eyJsb2dpbl91c2VyX2tleSI6IjM1OmVjZTkyMWQ1MzY2NDRkMmRhZTU0YmU0ZjA4ODE0OWZkIn0.EXKwA8I8t5rK864aJqMEh51XZ8IPtjG3juV51mgJf80
Accept: application/json
Accept: application/json
...
...
base-manager/src/test/java/com/mortals/httpclient/skin/SkinFieldController.http
View file @
219a9283
###皮肤属性字段配置列表
###皮肤属性字段配置列表
POST {{baseUrl}}/skin/field/list
POST {{baseUrl}}/skin/field/list
Authorization: {{authToken}}
Content-Type: application/json
Content-Type: application/json
{
{
"page":1,
"page":1,
"size":10
"size":10,
"skinId": 0
}
}
...
...
base-manager/src/test/java/com/mortals/httpclient/system/system.http
View file @
219a9283
...
@@ -4,8 +4,8 @@ POST {{baseUrl}}/login/login
...
@@ -4,8 +4,8 @@ POST {{baseUrl}}/login/login
Content-Type: application/json
Content-Type: application/json
{
{
"loginName":"
admin
",
"loginName":"
xiaoyi
",
"password":"
admin
",
"password":"
xiaoyi
",
"securityCode":"8888"
"securityCode":"8888"
}
}
...
...
smart-gateway/pom.xml
View file @
219a9283
...
@@ -42,6 +42,9 @@
...
@@ -42,6 +42,9 @@
<profiles.kafka.brokers>
192.168.0.251:9092
</profiles.kafka.brokers>
<profiles.kafka.brokers>
192.168.0.251:9092
</profiles.kafka.brokers>
<profiles.rabbitmq.host>
192.168.0.98
</profiles.rabbitmq.host>
<profiles.rabbitmq.host>
192.168.0.98
</profiles.rabbitmq.host>
<profiles.rabbitmq.port>
5672
</profiles.rabbitmq.port>
<profiles.rabbitmq.port>
5672
</profiles.rabbitmq.port>
<profiles.rabbitmq.username>
taxi_mq
</profiles.rabbitmq.username>
<profiles.rabbitmq.password>
admin@2020
</profiles.rabbitmq.password>
<profiles.rabbitmq.virtualhost>
/test
</profiles.rabbitmq.virtualhost>
<profiles.nacos.server-addr>
192.168.0.252:8848
</profiles.nacos.server-addr>
<profiles.nacos.server-addr>
192.168.0.252:8848
</profiles.nacos.server-addr>
<profiles.nacos.group>
DEFAULT_GROUP
</profiles.nacos.group>
<profiles.nacos.group>
DEFAULT_GROUP
</profiles.nacos.group>
<profiles.nacos.namespace>
smart-gov
</profiles.nacos.namespace>
<profiles.nacos.namespace>
smart-gov
</profiles.nacos.namespace>
...
@@ -89,7 +92,14 @@
...
@@ -89,7 +92,14 @@
<artifactId>
spring-cloud-starter-loadbalancer
</artifactId>
<artifactId>
spring-cloud-starter-loadbalancer
</artifactId>
</dependency>
</dependency>
<!-- <dependency>
<!-- 实现对 RabbitMQ 的自动化配置 -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-amqp
</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>-->
</dependency>-->
...
...
smart-gateway/src/main/java/com/mortals/xhx/base/framework/config/RabbitConfig.java
0 → 100644
View file @
219a9283
package
com.mortals.xhx.base.framework.config
;
import
com.mortals.xhx.common.key.QueueKey
;
import
org.springframework.amqp.core.Binding
;
import
org.springframework.amqp.core.BindingBuilder
;
import
org.springframework.amqp.core.DirectExchange
;
import
org.springframework.amqp.core.Queue
;
import
org.springframework.amqp.rabbit.AsyncRabbitTemplate
;
import
org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory
;
import
org.springframework.amqp.rabbit.connection.ConnectionFactory
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.amqp.support.converter.Jackson2JsonMessageConverter
;
import
org.springframework.amqp.support.converter.MessageConverter
;
import
org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
java.util.HashMap
;
import
java.util.Map
;
@Configuration
public
class
RabbitConfig
{
public
Integer
messageTtl
=
86400000
;
public
Map
<
String
,
Object
>
args
=
new
HashMap
<>();
// 创建 Queue
@Bean
public
Queue
accessLogQueue
()
{
args
.
put
(
"x-message-ttl"
,
messageTtl
);
return
new
Queue
(
QueueKey
.
ACCESS_LOG_QUEUE
,
// Queue 名字
true
,
// durable: 是否持久化
false
,
// exclusive: 是否排它
false
,
args
);
// autoDelete: 是否自动删除
}
@Bean
public
Queue
bizLogQueue
()
{
args
.
put
(
"x-message-ttl"
,
messageTtl
);
return
new
Queue
(
QueueKey
.
BIZ_LOG_QUEUE
,
// Queue 名字
true
,
// durable: 是否持久化
false
,
// exclusive: 是否排它
false
,
args
);
// autoDelete: 是否自动删除
}
@Bean
public
Queue
errorLogQueue
()
{
return
new
Queue
(
QueueKey
.
ERROR_LOG_QUEUE
,
// Queue 名字
true
,
// durable: 是否持久化
false
,
// exclusive: 是否排它
false
,
args
);
// autoDelete: 是否自动删除
}
@Bean
public
Queue
operationLogQueue
()
{
return
new
Queue
(
QueueKey
.
OPERATION_LOG_QUEUE
,
// Queue 名字
true
,
// durable: 是否持久化
false
,
// exclusive: 是否排它
false
,
args
);
// autoDelete: 是否自动删除
}
// 创建 Direct Exchange
@Bean
public
DirectExchange
exchange
()
{
return
new
DirectExchange
(
QueueKey
.
EXCHANGE
,
true
,
// durable: 是否持久化
false
);
// exclusive: 是否排它
}
// 创建 Binding
@Bean
public
Binding
accessBinding
()
{
return
BindingBuilder
.
bind
(
accessLogQueue
()).
to
(
exchange
()).
with
(
QueueKey
.
ACCESS_LOG_QUEUE
);
}
@Bean
public
Binding
bizBinding
()
{
return
BindingBuilder
.
bind
(
bizLogQueue
()).
to
(
exchange
()).
with
(
QueueKey
.
BIZ_LOG_QUEUE
);
}
@Bean
public
Binding
errorBinding
()
{
return
BindingBuilder
.
bind
(
errorLogQueue
()).
to
(
exchange
()).
with
(
QueueKey
.
ERROR_LOG_QUEUE
);
}
@Bean
public
Binding
operBinding
()
{
return
BindingBuilder
.
bind
(
operationLogQueue
()).
to
(
exchange
()).
with
(
QueueKey
.
OPERATION_LOG_QUEUE
);
}
@Bean
(
name
=
"consumerBatchContainerFactory"
)
public
SimpleRabbitListenerContainerFactory
consumerBatchContainerFactory
(
SimpleRabbitListenerContainerFactoryConfigurer
configurer
,
ConnectionFactory
connectionFactory
)
{
// 创建 SimpleRabbitListenerContainerFactory 对象
SimpleRabbitListenerContainerFactory
factory
=
new
SimpleRabbitListenerContainerFactory
();
configurer
.
configure
(
factory
,
connectionFactory
);
// 额外添加批量消费的属性
factory
.
setBatchListener
(
true
);
factory
.
setBatchSize
(
10
);
factory
.
setReceiveTimeout
(
30
*
1000L
);
factory
.
setConsumerBatchEnabled
(
true
);
return
factory
;
}
//修改系列和与反序列化转换器
@Bean
public
MessageConverter
messageConverter
()
{
return
new
Jackson2JsonMessageConverter
();
}
@Bean
public
AsyncRabbitTemplate
asyncRabbitTemplate
(
RabbitTemplate
rabbitTemplate
)
{
AsyncRabbitTemplate
asyncRabbitTemplate
=
new
AsyncRabbitTemplate
(
rabbitTemplate
);
asyncRabbitTemplate
.
setReceiveTimeout
(
10000
);
return
asyncRabbitTemplate
;
}
}
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/GlobalCacheRequestFilter.java
View file @
219a9283
package
com.mortals.xhx.base.framework.filter
;
package
com.mortals.xhx.base.framework.filter
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.cloud.gateway.filter.GatewayFilterChain
;
import
org.springframework.cloud.gateway.filter.GatewayFilterChain
;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
import
org.springframework.cloud.gateway.support.ServerWebExchangeUtils
;
import
org.springframework.cloud.gateway.support.ServerWebExchangeUtils
;
...
@@ -15,11 +16,13 @@ import reactor.core.publisher.Mono;
...
@@ -15,11 +16,13 @@ import reactor.core.publisher.Mono;
* @author: zxfei
* @author: zxfei
* @date: 2022/6/20 16:59
* @date: 2022/6/20 16:59
*/
*/
//@Component
@Component
@Slf4j
public
class
GlobalCacheRequestFilter
implements
GlobalFilter
,
Ordered
{
public
class
GlobalCacheRequestFilter
implements
GlobalFilter
,
Ordered
{
@Override
@Override
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
log
.
info
(
"GlobalCacheRequestFilter:{}"
,
getOrder
());
// GET DELETE 不过滤
// GET DELETE 不过滤
HttpMethod
method
=
exchange
.
getRequest
().
getMethod
();
HttpMethod
method
=
exchange
.
getRequest
().
getMethod
();
if
(
method
==
null
||
method
==
HttpMethod
.
GET
||
method
==
HttpMethod
.
DELETE
)
{
if
(
method
==
null
||
method
==
HttpMethod
.
GET
||
method
==
HttpMethod
.
DELETE
)
{
...
...
smart-gateway/src/main/java/com/mortals/xhx/base/framework/filter/GlobalLogFilter.java
View file @
219a9283
package
com.mortals.xhx.base.framework.filter
;
package
com.mortals.xhx.base.framework.filter
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.util.IdUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.mortals.xhx.base.framework.config.CustomGatewayProperties
;
import
com.mortals.xhx.base.framework.config.CustomGatewayProperties
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -19,6 +20,7 @@ import org.springframework.web.util.UriComponentsBuilder;
...
@@ -19,6 +20,7 @@ import org.springframework.web.util.UriComponentsBuilder;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
reactor.core.publisher.Mono
;
import
javax.sound.midi.Track
;
import
java.net.URI
;
import
java.net.URI
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.LinkedHashSet
;
import
java.util.LinkedHashSet
;
...
@@ -32,19 +34,54 @@ import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.G
...
@@ -32,19 +34,54 @@ import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.G
* @date: 2022/6/20 17:00
* @date: 2022/6/20 17:00
*/
*/
@Slf4j
@Slf4j
//
@Component
@Component
public
class
GlobalLogFilter
implements
GlobalFilter
,
Ordered
{
public
class
GlobalLogFilter
implements
GlobalFilter
,
Ordered
{
@Autowired
@Autowired
private
CustomGatewayProperties
customGatewayProperties
;
private
CustomGatewayProperties
customGatewayProperties
;
private
static
final
String
START_TIME
=
"startTime"
;
private
static
final
String
START_TIME
=
"startTime"
;
private
static
final
String
TRACE_ID
=
"traceId"
;
@Override
@Override
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
log
.
info
(
"GlobalLogFilter:{}"
,
getOrder
());
//保存请求链路,设置数据追踪id到header中
if
(!
customGatewayProperties
.
getRequestLog
())
{
return
chain
.
filter
(
exchange
);
return
chain
.
filter
(
exchange
);
}
ServerHttpRequest
request
=
exchange
.
getRequest
();
String
path
=
getOriginalRequestUrl
(
exchange
);
String
url
=
request
.
getMethod
().
name
()
+
" "
+
path
;
//判断请求类型
if
(
isJsonRequest
(
request
))
{
//读取请求体后 内容需要重新设置进去
String
jsonParam
=
resolveBodyFromRequest
(
request
);
log
.
info
(
"开始请求 => URL[{}],参数类型[json],参数:[{}]"
,
url
,
jsonParam
);
}
else
{
//非json类型,
MultiValueMap
<
String
,
String
>
parameterMap
=
request
.
getQueryParams
();
if
(
MapUtil
.
isNotEmpty
(
parameterMap
))
{
log
.
info
(
"开始请求 => URL[{}],参数类型[param],参数:[{}]"
,
url
,
JSON
.
toJSONString
(
parameterMap
));
}
else
{
log
.
info
(
"开始请求 => URL[{}],无参数"
,
url
);
}
}
exchange
.
getAttributes
().
put
(
START_TIME
,
System
.
currentTimeMillis
());
exchange
.
getRequest
().
getHeaders
().
add
(
TRACE_ID
,
IdUtil
.
fastSimpleUUID
());
return
chain
.
filter
(
exchange
).
then
(
Mono
.
fromRunnable
(()
->
{
Long
startTime
=
exchange
.
getAttribute
(
START_TIME
);
if
(
startTime
!=
null
)
{
long
executeTime
=
(
System
.
currentTimeMillis
()
-
startTime
);
log
.
info
(
"结束请求 => URL[{}],耗时:[{}]毫秒"
,
url
,
executeTime
);
}
}));
//return chain.filter(exchange);
/* if (!customGatewayProperties.getRequestLog()) {
/* if (!customGatewayProperties.getRequestLog()) {
return chain.filter(exchange);
return chain.filter(exchange);
...
...
smart-gateway/src/main/java/com/mortals/xhx/common/key/QueueKey.java
0 → 100644
View file @
219a9283
package
com.mortals.xhx.common.key
;
/**
* rabbit 队列key定义
*/
public
class
QueueKey
{
public
static
final
String
ACCESS_LOG_QUEUE
=
"ACCESS_LOG_QUEUE"
;
public
static
final
String
BIZ_LOG_QUEUE
=
"BIZ_LOG_QUEUE"
;
public
static
final
String
ERROR_LOG_QUEUE
=
"ERROR_LOG_QUEUE"
;
public
static
final
String
OPERATION_LOG_QUEUE
=
"OPERATION_LOG_QUEUE"
;
public
static
final
String
EXCHANGE
=
"LOG"
;
public
static
final
String
ROUTING_KEY
=
"LOG_ROUTING_KEY"
;
}
smart-gateway/src/main/resources/bootstrap.yml
View file @
219a9283
...
@@ -13,6 +13,12 @@ spring:
...
@@ -13,6 +13,12 @@ spring:
multipart
:
multipart
:
maxFileSize
:
100Mb
maxFileSize
:
100Mb
maxRequestSize
:
1000Mb
maxRequestSize
:
1000Mb
rabbitmq
:
host
:
@
profiles.rabbitmq.host@
port
:
@
profiles.rabbitmq.port@
username
:
@
profiles.rabbitmq.username@
password
:
@
profiles.rabbitmq.password@
virtualHost
:
@
profiles.rabbitmq.virtualhost@
cloud
:
cloud
:
# 网关配置
# 网关配置
gateway
:
gateway
:
...
@@ -56,6 +62,12 @@ spring:
...
@@ -56,6 +62,12 @@ spring:
uri
:
lb://device-manager
uri
:
lb://device-manager
predicates
:
predicates
:
-
Path=/m/**
-
Path=/m/**
# 日志服务
-
id
:
log-manager
# uri: http://127.0.0.1:17211
uri
:
lb://log-manager
predicates
:
-
Path=/logservice/**
nacos
:
nacos
:
# Nacos 作为注册中心的配置项,对应 NacosDiscoveryProperties 配置类
# Nacos 作为注册中心的配置项,对应 NacosDiscoveryProperties 配置类
discovery
:
discovery
:
...
...
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