feat: introduce middleware rabbitmq and redis
This commit is contained in:
@@ -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); // 持久化队列
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user