feat: introduce middleware rabbitmq and redis

This commit is contained in:
merlin
2025-12-11 10:37:03 +08:00
parent a1a23bec7a
commit 44133d3667
22 changed files with 404 additions and 42 deletions

View File

@@ -0,0 +1,16 @@
package xin.merlin.myplayerbackend.config;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RabbitMQConfig {
public static final String WS_MESSAGE_QUEUE = "ws.message";
@Bean
public Queue wsMessageQueue() {
return new Queue(WS_MESSAGE_QUEUE, true); // 持久化队列
}
}

View File

@@ -0,0 +1,24 @@
package xin.merlin.myplayerbackend.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(factory);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
return template;
}
}

View File

@@ -26,6 +26,10 @@ public class WebsocketInterceptor implements HandshakeInterceptor {
String token = request.getHeaders().getFirst("Authorization");
if (token != null && token.startsWith("Bearer ")) {
token = token.substring(7);
if (jwtUtil.isTokenExpired(token)){
log.info("token expired");
return false;
}
} else {
return false;
}