-
Notifications
You must be signed in to change notification settings - Fork 5
WEB - (준)실시간 경로 #340
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
Merged
WEB - (준)실시간 경로 #340
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d08762e
임시 커밋
ji-won-2 0bf382b
Merge branch 'develop' of https://github.com/Kernel360/KDEV4-TRACKY-B…
ji-won-2 fed0b09
준실시간 경로를 위한 sse 연결
ji-won-2 7c9cc54
출발 시점부터 현재까지의 경로를 위한 api 복구
ji-won-2 fd15893
feat: 실시간 경로 api
ji-won-2 cf1165d
feat: develop merge
ji-won-2 8845557
Merge branch 'develop' of https://github.com/Kernel360/KDEV4-TRACKY-B…
ji-won-2 7d87d57
실시간
ji-won-2 dd375c9
수정
ji-won-2 9babf08
Update application-common.yml
ji-won-2 d3cec7a
Update EventEmitterService.java
ji-won-2 fc67473
Update EventSseController.java
ji-won-2 29e3e1a
수정
ji-won-2 819b1af
Merge branch 'develop' of https://github.com/Kernel360/KDEV4-TRACKY-B…
ji-won-2 a09f41d
Merge branch 'feat/real-path' of https://github.com/Kernel360/KDEV4-T…
ji-won-2 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
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
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 |
|---|---|---|
|
|
@@ -13,55 +13,79 @@ | |
| @Slf4j | ||
| @Service | ||
| public class EventEmitterService { | ||
| private final Map<String, SseEmitter> emitters = new ConcurrentHashMap<>(); | ||
| private static final Map<String, SseEmitter> emitters = new ConcurrentHashMap<>(); | ||
|
|
||
| public static Map<String, SseEmitter> getTest() { | ||
|
||
| return emitters; | ||
| } | ||
|
|
||
| public SseEmitter subscribe(String driveId) { | ||
|
|
||
| SseEmitter oldEmitter = emitters.get(driveId); | ||
| if (oldEmitter != null) { | ||
| oldEmitter.complete(); // 연결 종료 | ||
| emitters.remove(driveId); | ||
| log.info("기존 SSE 연결 종료: driveId = {}", driveId); | ||
| } | ||
|
|
||
| public SseEmitter subscribe(String clientId) { | ||
| SseEmitter emitter = new SseEmitter(30 * 60 * 1000L); | ||
| emitters.put(clientId, emitter); | ||
|
|
||
| log.info("SSE 구독 연결: clientId = {}", clientId); | ||
| emitters.put(driveId, emitter); | ||
|
|
||
| emitter.onCompletion(() -> emitters.remove(clientId)); | ||
| emitter.onTimeout(() -> emitters.remove(clientId)); | ||
| emitter.onError((e) -> emitters.remove(clientId)); | ||
| log.info("SSE 연결: driveId = {}, emitter={}", driveId, emitter); | ||
|
|
||
| emitter.onCompletion(() -> { | ||
| log.info("SSE 연결 종료: driveId = {}", driveId); | ||
| emitters.remove(driveId); | ||
| }); | ||
|
|
||
| emitter.onTimeout(() -> emitters.remove(driveId)); | ||
| emitter.onError((e) -> emitters.remove(driveId)); | ||
|
|
||
| try { | ||
| emitter.send(SseEmitter.event().comment("connected")); | ||
|
|
||
| emitter.send(SseEmitter.event() | ||
| .name("init") | ||
| .data("SSE 연결 성공")); | ||
| } catch (Exception e) { | ||
| log.error("초기 SSE 메시지 전송 실패: clientId = {}", clientId, e); | ||
| log.error("초기 SSE 메시지 전송 실패: driveId = {}", driveId, e); | ||
| emitter.completeWithError(e); | ||
| emitters.remove(clientId); | ||
| emitters.remove(driveId); | ||
| } | ||
|
|
||
| return emitter; | ||
| } | ||
|
|
||
| public void sendEvent(String eventName, Object data) { | ||
| emitters.forEach((key, emitter) -> { | ||
| try { | ||
| emitter.send(SseEmitter.event() | ||
| .name(eventName) | ||
| .data(data)); | ||
| } catch (IOException e) { | ||
| log.warn("SSE 연결 실패 (eventName: {}): {}", eventName, e.getMessage()); | ||
| emitter.completeWithError(e); | ||
| emitters.remove(key); | ||
| } | ||
| }); | ||
| public void sendToDriveId(String driveId, String eventName, Object data) { | ||
| SseEmitter emitter = emitters.get(driveId); | ||
| log.info("emitters.get({}) 결과: {}", driveId, emitter); | ||
|
|
||
| if (emitter == null) { | ||
| log.warn("SSE 전송 실패: driveId={}, event={}", driveId, eventName); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| emitter.send(SseEmitter.event().name(eventName).data(data)); | ||
| log.info("emitter.send 성공"); | ||
| } catch (Exception e) { | ||
| log.error("emitter.send 실패: {}", e.getMessage(), e); | ||
| emitter.completeWithError(e); | ||
| emitters.remove(driveId); | ||
| } | ||
| } | ||
|
|
||
| // keep-alive 메시지를 15초마다 전송 | ||
| @Scheduled(fixedRate = 15000) | ||
| public void sendKeepAlive() { | ||
| emitters.forEach((clientId, emitter) -> { | ||
| emitters.forEach((driveId, emitter) -> { | ||
| try { | ||
| emitter.send(SseEmitter.event().comment("keep-alive")); | ||
| } catch (IOException e) { | ||
| log.warn("SSE keep-alive 실패: clientId = {}", clientId); | ||
| log.warn("SSE keep-alive 실패: driveId = {}", driveId); | ||
| emitter.completeWithError(e); | ||
| emitters.remove(clientId); | ||
| emitters.remove(driveId); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
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
23 changes: 23 additions & 0 deletions
23
tracky-web/src/main/java/kernel360/trackyweb/emitter/GpsPointResponse.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,23 @@ | ||
| package kernel360.trackyweb.emitter; | ||
|
|
||
| import kernel360.trackyweb.realtime.application.dto.request.CycleGpsRequest; | ||
|
|
||
| public record GpsPointResponse( | ||
| double lat, | ||
| double lon, | ||
| int ang, | ||
| int spd, | ||
| String oTime, | ||
| double sum | ||
| ) { | ||
| public static GpsPointResponse from(CycleGpsRequest req) { | ||
| return new GpsPointResponse( | ||
| req.gpsInfo().getLat(), | ||
| req.gpsInfo().getLon(), | ||
| req.gpsInfo().getAng(), | ||
| req.gpsInfo().getSpd(), | ||
| req.oTime().toString(), | ||
| req.gpsInfo().getSum() | ||
| ); | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static으로 두신 이유가 있나요?