-
Notifications
You must be signed in to change notification settings - Fork 4
Epic/chat 채팅구현 #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Epic/chat 채팅구현 #76
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
66dad11
feat: 기본 채팅 구현
Kyoungwoong e67193e
feat: 필터링 기본 기능 구현
Kyoungwoong 12f79b1
feat: 신고 기능 추가
Kyoungwoong af19f08
feat: 밴 유저 채팅기능 제한
Kyoungwoong 6008880
feat: 메시지 큐(카프카) 마이그레이션 및 실시간 채팅, 채팅 룸 생성&삭제, 채팅 필터 생성&삭제, 차단 유저 CRUD 적용
Kyoungwoong aa572a5
merge: dev into epic/chat
Kyoungwoong 2206d03
chore: 로그 추가 및 필요없는 코드 삭제 및 수정
Kyoungwoong 7cda880
feat: 유저 밴 적용시 슬랙 알람 적용
Kyoungwoong cc7d590
chore: 카프카 설정 개발계에 맞게 변경
Kyoungwoong 4b05029
Merge branch 'dev' into epic/chat
Kyoungwoong d2ec154
chore: Request 객체 생성
Kyoungwoong 05d3ed8
chore: ErrorCode 클래스 에러 수정
Kyoungwoong 2fba2b7
fix: Service의 특성에 따른 Read&Write 분리
Kyoungwoong c6a37f8
fix: Entity 에서 ResposneDTO로 변환
Kyoungwoong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package org.myteam.server.chat.config; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.myteam.server.chat.domain.ChatRoom; | ||
| import org.myteam.server.chat.repository.ChatRoomRepository; | ||
| import org.myteam.server.chat.domain.FilterData; | ||
| import org.myteam.server.chat.repository.FilterDataRepository; | ||
| import org.springframework.boot.CommandLineRunner; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class DataInit implements CommandLineRunner { | ||
|
|
||
| private final ChatRoomRepository repository; | ||
| private final FilterDataRepository filterDataRepository; | ||
|
|
||
| @Override | ||
| public void run(String... args) throws Exception { | ||
|
|
||
| ChatRoom chatRoom1 = new ChatRoom("맨유 VS 토트넘"); | ||
| ChatRoom chatRoom2 = new ChatRoom("아스날 VS 맨시티"); | ||
| ChatRoom chatRoom3 = new ChatRoom("첼시 VS 리버풀"); | ||
|
|
||
| repository.save(chatRoom1); | ||
| repository.save(chatRoom2); | ||
| repository.save(chatRoom3); | ||
|
|
||
| FilterData filterData1 = new FilterData("맹구"); | ||
| FilterData filterData2 = new FilterData("닭트넘"); | ||
|
|
||
| filterDataRepository.save(filterData1); | ||
| filterDataRepository.save(filterData2); | ||
|
|
||
| log.info("데이터 초기화 완료"); | ||
| } | ||
| } | ||
98 changes: 98 additions & 0 deletions
98
src/main/java/org/myteam/server/chat/config/KafkaConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package org.myteam.server.chat.config; | ||
|
|
||
|
|
||
| import org.apache.kafka.clients.admin.AdminClientConfig; | ||
| import org.apache.kafka.clients.consumer.ConsumerConfig; | ||
| import org.apache.kafka.clients.producer.ProducerConfig; | ||
| import org.apache.kafka.common.serialization.StringDeserializer; | ||
| import org.apache.kafka.common.serialization.StringSerializer; | ||
| import org.myteam.server.chat.domain.Chat; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.kafka.annotation.EnableKafka; | ||
| import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; | ||
| import org.springframework.kafka.core.*; | ||
| import org.springframework.kafka.support.serializer.JsonDeserializer; | ||
| import org.springframework.kafka.support.serializer.JsonSerializer; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| @EnableKafka | ||
| @Configuration | ||
| public class KafkaConfig { | ||
|
|
||
| private static final String BOOTSTRAP_SERVERS = "kafka:9092"; | ||
| private static final String DEFAULT_GROUP_ID = "chat-group"; | ||
|
|
||
| @Bean | ||
| public KafkaAdmin kafkaAdmin() { | ||
| Map<String, Object> configs = new HashMap<>(); | ||
| configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS); | ||
| return new KafkaAdmin(configs); | ||
| } | ||
|
|
||
| /** | ||
| * Kafka ProducerFactory를 생성하는 Bean 메서드 | ||
| */ | ||
| @Bean | ||
| public ProducerFactory<String, Chat> producerFactory() { | ||
| return new DefaultKafkaProducerFactory<>(producerConfigurations()); | ||
| } | ||
|
|
||
| /** | ||
| * Kafka Producer 구성을 위한 설정값들을 포함한 맵을 반환하는 메서드 | ||
| */ | ||
| @Bean | ||
| public Map<String, Object> producerConfigurations() { | ||
| Map<String, Object> producerConfigurations = new HashMap<>(); | ||
|
|
||
| producerConfigurations.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS); | ||
| producerConfigurations.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); | ||
| producerConfigurations.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class); | ||
| producerConfigurations.put(JsonSerializer.ADD_TYPE_INFO_HEADERS, false); // JSON 타입 헤더 제거 (선택사항) | ||
|
|
||
| return producerConfigurations; | ||
| } | ||
|
|
||
| /** | ||
| * KafkaTemplate을 생성하는 Bean 메서드 | ||
| */ | ||
| @Bean | ||
| public KafkaTemplate<String, Chat> kafkaTemplate() { | ||
| return new KafkaTemplate<>(producerFactory()); | ||
| } | ||
|
|
||
| /** | ||
| * Kafka ConsumerFactory를 생성하는 Bean 메서드 | ||
| */ | ||
| @Bean | ||
| public ConsumerFactory<String, Chat> consumerFactory() { | ||
| JsonDeserializer<Chat> deserializer = new JsonDeserializer<>(Chat.class); | ||
| deserializer.addTrustedPackages("*"); // 모든 패키지 신뢰 (필요 시 제한적으로 변경) | ||
|
|
||
| Map<String, Object> consumerConfigurations = Map.of( | ||
| ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS, | ||
| ConsumerConfig.GROUP_ID_CONFIG, DEFAULT_GROUP_ID, | ||
| ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class, | ||
| ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, deserializer, | ||
| ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest" | ||
| ); | ||
|
|
||
| return new DefaultKafkaConsumerFactory<>(consumerConfigurations, new StringDeserializer(), deserializer); | ||
| } | ||
|
|
||
| /** | ||
| * KafkaListener 컨테이너 팩토리를 생성하는 Bean 메서드 | ||
| */ | ||
| @Bean | ||
| public ConcurrentKafkaListenerContainerFactory<String, Chat> kafkaListenerContainerFactory() { | ||
| ConcurrentKafkaListenerContainerFactory<String, Chat> factory = new ConcurrentKafkaListenerContainerFactory<>(); | ||
| factory.setConsumerFactory(consumerFactory()); | ||
|
|
||
| factory.setConcurrency(3); // 병렬 처리 설정 (기본값 1) | ||
| factory.getContainerProperties().setPollTimeout(3000L); // 폴링 시간 설정 (선택사항) | ||
|
|
||
| return factory; | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/myteam/server/chat/config/WebSocketConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package org.myteam.server.chat.config; | ||
|
|
||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.messaging.simp.config.MessageBrokerRegistry; | ||
| import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; | ||
| import org.springframework.web.socket.config.annotation.StompEndpointRegistry; | ||
| import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; | ||
| import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration; | ||
|
|
||
| @EnableWebSocketMessageBroker | ||
| @Configuration | ||
| @RequiredArgsConstructor | ||
| public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { | ||
|
|
||
| @Override | ||
| public void configureMessageBroker(MessageBrokerRegistry registry) { | ||
| registry.setApplicationDestinationPrefixes("/play-hive"); | ||
| registry.enableSimpleBroker("/room"); | ||
| } | ||
|
|
||
| @Override | ||
| public void registerStompEndpoints(StompEndpointRegistry registry) { | ||
| registry.addEndpoint("/ws-stomp") | ||
| .setAllowedOrigins("http://localhost:3000") | ||
| .withSockJS(); | ||
| registry.addEndpoint("/ws-stomp") | ||
| .setAllowedOrigins("http://localhost:3000"); | ||
| } | ||
|
|
||
| // STOMP에서 64KB 이상의 데이터 전송을 못하는 문제 해결 | ||
| @Override | ||
| public void configureWebSocketTransport(WebSocketTransportRegistration registry) { | ||
| registry.setMessageSizeLimit(160 * 64 * 1024); | ||
| registry.setSendTimeLimit(100 * 10000); | ||
| registry.setSendBufferSizeLimit(3 * 512 * 1024); | ||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
61
src/main/java/org/myteam/server/chat/controller/BanController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package org.myteam.server.chat.controller; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.myteam.server.chat.dto.request.BanRequest; | ||
| import org.myteam.server.chat.dto.response.BanResponse; | ||
| import org.myteam.server.chat.service.BanService; | ||
| import org.myteam.server.global.web.response.ResponseDto; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import static org.myteam.server.global.web.response.ResponseStatus.SUCCESS; | ||
|
|
||
| /** | ||
| * Ban 도메인에 대한 HTTP 요청 처리 | ||
| */ | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/bans") | ||
| public class BanController { | ||
|
|
||
| private final BanService banService; | ||
|
|
||
| /** | ||
| * 유저 밴하기 | ||
| */ | ||
| @PostMapping | ||
| public ResponseEntity<ResponseDto<BanResponse>> banUser(@RequestBody BanRequest request) { | ||
| BanResponse response = banService.banUser(request); | ||
| return ResponseEntity.ok(new ResponseDto( | ||
| SUCCESS.name(), | ||
| "Ban Success", | ||
| response | ||
| )); | ||
| } | ||
|
|
||
| /** | ||
| * 유저 밴 해제 | ||
| */ | ||
| @DeleteMapping("/{username}") | ||
| public ResponseEntity<ResponseDto<String>> unbanUser(@PathVariable String username) { | ||
| String deleteName = banService.unbanUser(username); | ||
| return ResponseEntity.ok(new ResponseDto( | ||
| SUCCESS.name(), | ||
| "Delete Ban Successfully", | ||
| deleteName | ||
| )); | ||
| } | ||
|
|
||
| /** | ||
| * 특정 유저 밴 정보 조회 | ||
| */ | ||
| @GetMapping("/{username}") | ||
| public ResponseEntity<ResponseDto<BanResponse>> getBanByUsername(@PathVariable String username) { | ||
| BanResponse response = banService.findBanByUsername(username); | ||
| return ResponseEntity.ok(new ResponseDto( | ||
| SUCCESS.name(), | ||
| "Find Ban Reason Successfully", | ||
| response | ||
| )); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.