Skip to content

Commit

Permalink
refactor: 채팅 서버에 만료 메시지를 보낼 수 있게 수정 및 테스트용 화면 sockJs 연결 대상을 dev-datah…
Browse files Browse the repository at this point in the history
…ub로 할 수 있게끔 변경
  • Loading branch information
mooncw committed Mar 22, 2024
1 parent a0025ec commit 2cde5b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import com.kernelsquare.memberapi.domain.alert.dto.AlertDto;
import com.kernelsquare.memberapi.domain.alert.mapper.AlertDtoMapper;
import com.kernelsquare.memberapi.domain.alert.service.AlertService;
import com.kernelsquare.memberapi.domain.coffeechat.dto.ChatMessageResponse;
import com.kernelsquare.memberapi.domain.coffeechat.dto.ChatMessageRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -26,7 +26,7 @@
@Component
@RequiredArgsConstructor
public class SchedulerManagerImpl implements ScheculerManager {
private final SimpMessageSendingOperations sendingOperations;
private final KafkaTemplate<String, Object> kafkaTemplate;
private final CoffeeChatReader coffeeChatReader;
private final QuestionReader questionReader;
private final AnswerReader answerReader;
Expand All @@ -42,15 +42,15 @@ public void disableChatRoom() {
chatRooms.forEach(chatRoom -> {
chatRoom.deactivateRoom();

ChatMessageResponse message = ChatMessageResponse.builder()
ChatMessageRequest message = ChatMessageRequest.builder()
.type(MessageType.EXPIRE)
.roomKey(chatRoom.getRoomKey())
.sender("system")
.message("채팅방 사용 시간이 만료되었습니다.")
.sendTime(LocalDateTime.now())
.build();

sendingOperations.convertAndSend("/topic/chat/room/" + message.getRoomKey(), message);
kafkaTemplate.send("chatting", message);
});
}

Expand Down
8 changes: 4 additions & 4 deletions member-api/src/main/resources/templates/chatscreen.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h2 th:text="${roomId}"></h2>
var sender = /*[[${sender}]]*/ '';
/*]]>*/
//alert(document.title);
var sock = new SockJS("/kernel-square");
var sock = new SockJS("http://localhost:8504/kernel-square");
var ws = Stomp.over(sock);
var reconnect = 0;
var vm = new Vue({
Expand All @@ -71,7 +71,7 @@ <h2 th:text="${roomId}"></h2>
('0' + now.getMinutes()).slice(-2) + ':' +
('0' + now.getSeconds()).slice(-2) + '.' +
('00' + now.getMilliseconds()).slice(-3) + 'Z';
ws.send("/app/chat/message", {}, JSON.stringify({type:'TALK', room_key:this.roomId, sender:this.sender, message:this.message, send_time:sendTime}));
ws.send("/app/chat/message", {}, JSON.stringify({type:'TALK', room_key:'dev', sender:this.sender, message:this.message, send_time:sendTime}));
this.message = '';
},
recvMessage: function(recv) {
Expand All @@ -86,7 +86,7 @@ <h2 th:text="${roomId}"></h2>
('0' + now.getMinutes()).slice(-2) + ':' +
('0' + now.getSeconds()).slice(-2) + '.' +
('00' + now.getMilliseconds()).slice(-3) + 'Z';
ws.send("/app/chat/message", {}, JSON.stringify({type:'LEAVE', room_key:this.roomId, sender:this.sender, send_time:sendTime}));
ws.send("/app/chat/message", {}, JSON.stringify({type:'LEAVE', room_key:'dev', sender:this.sender, send_time:sendTime}));
ws.disconnect();
}
}
Expand All @@ -111,7 +111,7 @@ <h2 th:text="${roomId}"></h2>
if(reconnect++ <= 5) {
setTimeout(function() {
console.log("connection reconnect");
sock = new SockJS("/kernel-square");
sock = new SockJS("http://localhost:8504/kernel-square");
ws = Stomp.over(sock);
connect();
},10*1000);
Expand Down

0 comments on commit 2cde5b5

Please sign in to comment.