feat : rabbitmq 추가
This commit is contained in:
parent
d94a09eea6
commit
ec0331e263
@ -22,6 +22,9 @@ dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'mysql:mysql-connector-java:8.0.33'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-websocket'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-amqp'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-reactor-netty'
|
||||
testImplementation 'org.springframework.amqp:spring-rabbit-test'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
implementation group: 'io.livekit', name: 'livekit-server', version: '0.6.1'
|
||||
implementation 'org.projectlombok:lombok'
|
||||
|
@ -38,6 +38,9 @@ public class BoardController {
|
||||
){
|
||||
List<ResponseBoardSummaryDto> boardSummaries = boardService.findBoards(pageNo, category, lectureId);
|
||||
|
||||
if(boardSummaries.isEmpty())
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
|
||||
return new ResponseEntity<>(boardSummaries, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
@ -14,35 +14,39 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@EnableWebMvc
|
||||
public class WebConfiguration implements WebMvcConfigurer {
|
||||
|
||||
private JWTInterceptor jwtInterceptor;
|
||||
|
||||
public WebConfiguration(JWTInterceptor jwtInterceptor) {
|
||||
super();
|
||||
this.jwtInterceptor = jwtInterceptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry
|
||||
.addMapping("/**")
|
||||
.allowedOrigins("http://i11a701.p.ssafy.io/", "http://localhost:5173", "http://localhost:4173")
|
||||
.allowedMethods(HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.PUT.name(),
|
||||
HttpMethod.DELETE.name(), HttpMethod.HEAD.name(), HttpMethod.OPTIONS.name(),
|
||||
HttpMethod.PATCH.name())
|
||||
.allowCredentials(true)
|
||||
.allowedHeaders("*")
|
||||
.maxAge(1800); // Pre-flight Caching
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/img/**").addResourceLocations("classpath:/static/assets/img/");
|
||||
registry.addResourceHandler("/*.html**").addResourceLocations("classpath:/static/");
|
||||
}
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(jwtInterceptor)
|
||||
.addPathPatterns("/**") // 모든 경로에 대해 인터셉터 적용
|
||||
.excludePathPatterns("/auth/**", "/board/**", "/user/**","/lecture/**","/qna/**"); // 인증 없이 접근 가능한 경로 설정
|
||||
}
|
||||
// private JWTInterceptor jwtInterceptor;
|
||||
//
|
||||
// public WebConfiguration(JWTInterceptor jwtInterceptor) {
|
||||
// super();
|
||||
//
|
||||
// this.jwtInterceptor = jwtInterceptor;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void addCorsMappings(CorsRegistry registry) {
|
||||
// registry
|
||||
// .addMapping("/**")
|
||||
// .allowedOrigins("http://i11a701.p.ssafy.io/", "http://localhost:5173", "http://localhost:4173")
|
||||
// .allowedMethods(HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.PUT.name(),
|
||||
// HttpMethod.DELETE.name(), HttpMethod.HEAD.name(), HttpMethod.OPTIONS.name(),
|
||||
// HttpMethod.PATCH.name())
|
||||
// .allowCredentials(true)
|
||||
// .allowedHeaders("*")
|
||||
// .maxAge(1800); // Pre-flight Caching
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
// registry.addResourceHandler("/img/**").addResourceLocations("classpath:/static/assets/img/");
|
||||
// registry.addResourceHandler("/*.html**").addResourceLocations("classpath:/static/");
|
||||
// }
|
||||
// @Override
|
||||
// public void addInterceptors(InterceptorRegistry registry) {
|
||||
// registry.addInterceptor(jwtInterceptor)
|
||||
//
|
||||
// .addPathPatterns("/**") // 모든 경로에 대해 인터셉터 적용
|
||||
// .excludePathPatterns("/v3/api-docs/**","/swagger-resources/**","/webjars/**","/swagger-ui/**","/auth/**", "/board/**", "/user/**","/lecture/**","/qna/**", "/quiz/**"); // 인증 없이 접근 가능한 경로 설정
|
||||
//
|
||||
// ///v3/api-docs/**, /swagger-resources/**, /webjars/**
|
||||
// }
|
||||
}
|
@ -12,8 +12,13 @@ public class WebSocketConfigurer implements WebSocketMessageBrokerConfigurer {
|
||||
|
||||
@Override
|
||||
public void configureMessageBroker(MessageBrokerRegistry registry) {
|
||||
registry.enableSimpleBroker("/sub");
|
||||
registry.setApplicationDestinationPrefixes("/pub");
|
||||
registry.setApplicationDestinationPrefixes("/pub")
|
||||
.enableStompBrokerRelay("/topic")
|
||||
.setRelayHost("localhost")
|
||||
.setVirtualHost("/")
|
||||
.setRelayPort(61613)
|
||||
.setClientLogin("guest")
|
||||
.setClientPasscode("guest");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,10 +16,14 @@ import org.springframework.messaging.handler.annotation.SendTo;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
import org.springframework.messaging.simp.SimpMessageSendingOperations;
|
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.socket.messaging.SessionConnectedEvent;
|
||||
import org.springframework.web.socket.messaging.SessionDisconnectEvent;
|
||||
import org.springframework.web.socket.messaging.SessionSubscribeEvent;
|
||||
import org.springframework.web.socket.messaging.SessionUnsubscribeEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -38,34 +42,36 @@ public class ChatController {
|
||||
this.jwtUtil = jwtUtil;
|
||||
}
|
||||
|
||||
// @GetMapping("/chat/enter/{lectureId}")
|
||||
// public ResponseEntity<?> enter(@PathVariable long lectureId){
|
||||
// List<ChatUserDto> chatUsers = chatService.findChatUsers(lectureId);
|
||||
//
|
||||
// return new ResponseEntity<>(chatUsers, HttpStatus.OK);
|
||||
// }
|
||||
@GetMapping("/chat/enter/{lectureId}")
|
||||
public ResponseEntity<?> enter(@PathVariable long lectureId){
|
||||
List<ChatUserDto> chatUsers = chatService.findChatUsers(lectureId);
|
||||
|
||||
return new ResponseEntity<>(chatUsers, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
// @MessageMapping("/hello/{channelId}")
|
||||
// @SendTo("/sub/channel/{channelId}")
|
||||
// public ChatUserDto hello(@DestinationVariable long channelId, SimpMessageHeaderAccessor simpMessageHeaderAccessor, @Header("Authorization") String token){
|
||||
// String sessionId = simpMessageHeaderAccessor.getSessionId();
|
||||
//
|
||||
// System.out.println("session" + sessionId);
|
||||
//
|
||||
// long userId = Long.parseLong(jwtUtil.getUserId(token));
|
||||
//
|
||||
// chatService.saveChatUserInfo(userId, channelId, sessionId);
|
||||
//
|
||||
// return chatService.getChatUserInfo(userId);
|
||||
// }
|
||||
@MessageMapping("/hello/{channelId}")
|
||||
@SendTo("/topic/{channelId}")
|
||||
public ChatUserDto hello(@DestinationVariable long channelId, SimpMessageHeaderAccessor simpMessageHeaderAccessor, @Header("Authorization") String token){
|
||||
String sessionId = simpMessageHeaderAccessor.getSessionId();
|
||||
|
||||
System.out.println("session" + sessionId);
|
||||
|
||||
System.out.println("가냐?????"+token);
|
||||
|
||||
long userId = Long.parseLong(jwtUtil.getUserId(token));
|
||||
|
||||
chatService.saveChatUserInfo(userId, channelId, sessionId);
|
||||
|
||||
return chatService.getChatUserInfo(userId);
|
||||
}
|
||||
|
||||
@MessageMapping("/message/{lectureId}")
|
||||
@SendTo("/sub/channel/{lectureId}")
|
||||
@SendTo("/topic/{lectureId}")
|
||||
public MessageDto sendMessage(@DestinationVariable long lectureId, MessageDto messageDto){return messageDto;}
|
||||
|
||||
@MessageMapping("/quiz/{lectureId}")
|
||||
@SendTo("/sub/channel/{lectureId}")
|
||||
@SendTo("/topic/{lectureId}")
|
||||
public QuizDto quizStart(@DestinationVariable long lectureId, QuizDto quizDto){
|
||||
return quizDto;
|
||||
}
|
||||
@ -88,5 +94,6 @@ public class ChatController {
|
||||
// chatService.deleteChatUserInfo(chatUserDto.getUserId());
|
||||
// simpMessageSendingOperations.convertAndSend("/sub/channel/" + chatUserDto.getLectureId(), chatUserDto);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user