Commit 364550b6 authored by 赵啸非's avatar 赵啸非

修改网关日志

parent dc1d564c
......@@ -29,7 +29,7 @@
<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.rabbitmq.virtualhost>/</profiles.rabbitmq.virtualhost>
<profiles.nacos.server-addr>192.168.0.252:8848</profiles.nacos.server-addr>
<profiles.nacos.group>DEFAULT_GROUP</profiles.nacos.group>
<profiles.nacos.namespace>smart-gov</profiles.nacos.namespace>
......@@ -47,7 +47,7 @@
<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.rabbitmq.virtualhost>/</profiles.rabbitmq.virtualhost>
<profiles.nacos.server-addr>192.168.0.252:8848</profiles.nacos.server-addr>
<profiles.nacos.group>DEFAULT_GROUP</profiles.nacos.group>
<profiles.nacos.namespace>smart-gov</profiles.nacos.namespace>
......
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;
......@@ -15,81 +10,8 @@ import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainer
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(
......
......@@ -35,7 +35,7 @@ import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.O
* @date: 2022/8/18 13:48
* @description:
**/
//@Component
@Component
@Slf4j
public class GatewayResponseFilter implements GlobalFilter, Ordered {
......
......@@ -96,6 +96,7 @@ public class GlobalLogFilter implements GlobalFilter, Ordered {
accessLogPdu.setRequestParam(paramStr);
accessLogPdu.setLogTime(new Date());
accessLogPdu.setMethod(method);
accessLogPdu.setUri(path);
messageProducer.syncAccessSend(accessLogPdu);
exchange.getAttributes().put(START_TIME, System.currentTimeMillis());
......
package com.mortals.xhx.base.framework.service;
import com.alibaba.fastjson.JSON;
import com.mortals.xhx.common.key.QueueKey;
import com.mortals.xhx.common.pdu.access.AccessLogPdu;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
......@@ -13,7 +14,7 @@ public class MessageProducer {
private RabbitTemplate rabbitTemplate;
public void syncAccessSend(AccessLogPdu accessLogPdu) {
rabbitTemplate.convertAndSend(QueueKey.EXCHANGE, QueueKey.BIZ_LOG_QUEUE, accessLogPdu);
rabbitTemplate.convertAndSend(QueueKey.EXCHANGE, QueueKey.ACCESS_LOG_QUEUE, JSON.toJSONString(accessLogPdu));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment