Compare commits
3 Commits
bda83a1bfe
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17a52ed471 | ||
|
|
b987c11cd1 | ||
|
|
62a521388d |
@@ -13,6 +13,7 @@ public class SaTokenConfig implements WebMvcConfigurer {
|
|||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
// 注册注解拦截器,并排除不需要注解鉴权的接口地址 (与登录拦截器无关)
|
// 注册注解拦截器,并排除不需要注解鉴权的接口地址 (与登录拦截器无关)
|
||||||
registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
|
registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
|
||||||
.addPathPatterns("/**");
|
.addPathPatterns("/**")
|
||||||
|
.excludePathPatterns("/swagger-ui/**");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.ivmiku.tutorial.config;
|
||||||
|
|
||||||
|
import jakarta.servlet.ServletContext;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import org.springframework.boot.web.servlet.ServletContextInitializer;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||||
|
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;
|
||||||
|
import org.springframework.web.util.WebAppRootListener;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class WebSocketConfig implements ServletContextInitializer {
|
||||||
|
@Bean
|
||||||
|
public ServerEndpointExporter serverEndpointExporter (){
|
||||||
|
return new ServerEndpointExporter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartup(ServletContext servletContext) throws ServletException {
|
||||||
|
servletContext.addListener(WebAppRootListener.class);
|
||||||
|
servletContext.setInitParameter("org.apache.tomcat.websocket.textBufferSize","102400000");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ServletServerContainerFactoryBean createWebSocketContainer() {
|
||||||
|
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
|
||||||
|
// 在此处设置bufferSize
|
||||||
|
container.setMaxTextMessageBufferSize(50*1024*1024);
|
||||||
|
container.setMaxBinaryMessageBufferSize(50*1024*1024);
|
||||||
|
container.setMaxSessionIdleTimeout(15 * 60000L);
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ import cn.dev33.satoken.annotation.SaCheckLogin;
|
|||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
import com.ivmiku.tutorial.entity.Comment;
|
import com.ivmiku.tutorial.entity.Comment;
|
||||||
import com.ivmiku.tutorial.entity.Pages;
|
import com.ivmiku.tutorial.entity.Pages;
|
||||||
import com.ivmiku.tutorial.response.AtNotifier;
|
import com.ivmiku.tutorial.response.AtNotifier;
|
||||||
@@ -13,7 +12,6 @@ import com.ivmiku.tutorial.service.CommentService;
|
|||||||
import com.ivmiku.tutorial.service.FileService;
|
import com.ivmiku.tutorial.service.FileService;
|
||||||
import com.ivmiku.tutorial.util.MyRedisUtil;
|
import com.ivmiku.tutorial.util.MyRedisUtil;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import org.apiguardian.api.API;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
@@ -21,7 +19,6 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 评论控制器,用于处理评论相关的HTTP请求。
|
* 评论控制器,用于处理评论相关的HTTP请求。
|
||||||
@@ -44,7 +41,7 @@ public class CommentController {
|
|||||||
private RabbitTemplate rabbitTemplate;
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private MyRedisUtil redisUtil;
|
private MyRedisUtil myRedisUtil;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,7 +80,7 @@ public class CommentController {
|
|||||||
notifier.setToId(mentionedUserId);
|
notifier.setToId(mentionedUserId);
|
||||||
notifier.setPostId(String.valueOf(comment.getCommentId()));
|
notifier.setPostId(String.valueOf(comment.getCommentId()));
|
||||||
rabbitTemplate.convertAndSend("exchange2", "", JSON.toJSONString(notifier));
|
rabbitTemplate.convertAndSend("exchange2", "", JSON.toJSONString(notifier));
|
||||||
redisUtil.listAdd("at:" + notifier.getToId(), JSON.toJSONString(notifier));
|
myRedisUtil.listAdd("at:" + notifier.getToId(), JSON.toJSONString(notifier));
|
||||||
}
|
}
|
||||||
return Result.ok(comment);
|
return Result.ok(comment);
|
||||||
}
|
}
|
||||||
@@ -131,7 +128,7 @@ public class CommentController {
|
|||||||
notifier.setToId(mentionedUserId);
|
notifier.setToId(mentionedUserId);
|
||||||
notifier.setPostId(String.valueOf(reply.getCommentId()));
|
notifier.setPostId(String.valueOf(reply.getCommentId()));
|
||||||
rabbitTemplate.convertAndSend("exchange2", "", JSON.toJSONString(notifier));
|
rabbitTemplate.convertAndSend("exchange2", "", JSON.toJSONString(notifier));
|
||||||
redisUtil.listAdd("at:" + notifier.getToId(), JSON.toJSONString(notifier));
|
myRedisUtil.listAdd("at:" + notifier.getToId(), JSON.toJSONString(notifier));
|
||||||
}
|
}
|
||||||
return Result.ok(reply);
|
return Result.ok(reply);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import com.ivmiku.tutorial.service.impl.SearchService;
|
|||||||
import jakarta.websocket.*;
|
import jakarta.websocket.*;
|
||||||
import jakarta.websocket.server.PathParam;
|
import jakarta.websocket.server.PathParam;
|
||||||
import jakarta.websocket.server.ServerEndpoint;
|
import jakarta.websocket.server.ServerEndpoint;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -18,7 +20,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@ServerEndpoint(value = "/search/{satoken}")
|
@ServerEndpoint(value = "/search/{satoken}")
|
||||||
public class WebSocketServer {
|
public class WebSocketServer implements ApplicationContextAware {
|
||||||
public static Map<String, Session> sessionMap = new ConcurrentHashMap<>();
|
public static Map<String, Session> sessionMap = new ConcurrentHashMap<>();
|
||||||
private static ApplicationContext applicationContext;
|
private static ApplicationContext applicationContext;
|
||||||
private SearchService searchService;
|
private SearchService searchService;
|
||||||
@@ -61,7 +63,7 @@ public class WebSocketServer {
|
|||||||
}
|
}
|
||||||
case '#' -> {
|
case '#' -> {
|
||||||
String sub = message.substring(1);
|
String sub = message.substring(1);
|
||||||
List<String> list = searchService.getTag(message);
|
List<String> list = searchService.getTag(sub);
|
||||||
session.getBasicRemote().sendText(JSON.toJSONString(Result.ok(list)));
|
session.getBasicRemote().sendText(JSON.toJSONString(Result.ok(list)));
|
||||||
}
|
}
|
||||||
//预留给社区搜索
|
//预留给社区搜索
|
||||||
@@ -70,4 +72,9 @@ public class WebSocketServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
|
WebSocketServer.applicationContext = applicationContext;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ public class SaTokenConfigure {
|
|||||||
"/user/register",
|
"/user/register",
|
||||||
"/swagger-resources/**",
|
"/swagger-resources/**",
|
||||||
"/v3/**",
|
"/v3/**",
|
||||||
"/swagger-ui/**")
|
"/swagger-ui/**",
|
||||||
|
"/ws/**")
|
||||||
// 鉴权方法:每次访问进入
|
// 鉴权方法:每次访问进入
|
||||||
.setAuth(obj -> {
|
.setAuth(obj -> {
|
||||||
// 登录校验 -- 拦截所有路由,并排除指定路由
|
// 登录校验 -- 拦截所有路由,并排除指定路由
|
||||||
|
|||||||
@@ -26,3 +26,7 @@ spring.cloud.gateway.routes[2].filters[0]=StripPrefix=1
|
|||||||
spring.cloud.gateway.routes[3].id=websocket
|
spring.cloud.gateway.routes[3].id=websocket
|
||||||
spring.cloud.gateway.routes[3].uri=lb:ws://user
|
spring.cloud.gateway.routes[3].uri=lb:ws://user
|
||||||
spring.cloud.gateway.routes[3].predicates[0]=Path=/chat/**
|
spring.cloud.gateway.routes[3].predicates[0]=Path=/chat/**
|
||||||
|
|
||||||
|
spring.cloud.gateway.routes[4].id=search
|
||||||
|
spring.cloud.gateway.routes[4].uri=lb:ws://community
|
||||||
|
spring.cloud.gateway.routes[4].predicates[0]=Path=/search/**
|
||||||
@@ -25,3 +25,7 @@ spring.cloud.gateway.routes[2].filters[0]=StripPrefix=1
|
|||||||
spring.cloud.gateway.routes[3].id=websocket
|
spring.cloud.gateway.routes[3].id=websocket
|
||||||
spring.cloud.gateway.routes[3].uri=lb:ws://user
|
spring.cloud.gateway.routes[3].uri=lb:ws://user
|
||||||
spring.cloud.gateway.routes[3].predicates[0]=Path=/chat/**
|
spring.cloud.gateway.routes[3].predicates[0]=Path=/chat/**
|
||||||
|
|
||||||
|
spring.cloud.gateway.routes[4].id=search
|
||||||
|
spring.cloud.gateway.routes[4].uri=lb:ws://community
|
||||||
|
spring.cloud.gateway.routes[4].predicates[0]=Path=/search/**
|
||||||
Reference in New Issue
Block a user