Skip to content

Commit

Permalink
chore: SSE test
Browse files Browse the repository at this point in the history
  • Loading branch information
clean2001 committed Sep 5, 2024
1 parent 1eb1c97 commit cb02e10
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/devjeans/sid/config/RedisConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,13 @@ public RedisTemplate<String, Object> ssePubSubTemplate(@Qualifier("ssePubSub") R
return redisTemplate;
}

@Bean
@Qualifier("ssePubSub")
public RedisMessageListenerContainer redisMessageListenerContainer(@Qualifier("ssePubSub") RedisConnectionFactory sseFactory) {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(sseFactory);
return container;
}
// @Bean
// @Qualifier("ssePubSub")
// public RedisMessageListenerContainer redisMessageListenerContainer(@Qualifier("ssePubSub") RedisConnectionFactory sseFactory) {
// RedisMessageListenerContainer container = new RedisMessageListenerContainer();
// container.setConnectionFactory(sseFactory);
// return container;
// }

// // redis에 메시지 발행되면 listen하게 되고 , 아래 코드를 통해 특정 메서드를 실행하도록 설정
// @Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class SseService implements MessageListener {
private final SecurityUtil securityUtil;
private final AlertRepository alertRepository;

@Qualifier("ssePubSub")
// @Qualifier("ssePubSub")
private final RedisMessageListenerContainer redisMessageListenerContainer;
private final ConnectedMap connectedMap;

Expand All @@ -61,8 +61,7 @@ public SseService(@Qualifier("ssePubSub")
RedisTemplate<String, Object> sseRedisTemplate,
SecurityUtil securityUtil,
AlertRepository alertRepository,
// @Qualifier("ssePubSub")
@Qualifier("ssePubSub") RedisMessageListenerContainer redisMessageListenerContainer,
RedisMessageListenerContainer redisMessageListenerContainer,
ConnectedMap connectedMap) {
this.sseRedisTemplate = sseRedisTemplate;
this.securityUtil = securityUtil;
Expand Down Expand Up @@ -118,7 +117,7 @@ public void publishMessage(RedisRes redisRes, Long memberId) {
// throw new RuntimeException(e);
// }
// }else{
sseRedisTemplate.convertAndSend(String.valueOf(memberId), redisRes);
sseRedisTemplate.convertAndSend(String.valueOf(memberId), redisRes);
// }
}

Expand All @@ -142,14 +141,14 @@ public void onMessage(Message message, byte[] pattern) {
}

// if (emitter != null) {
emitter.send(SseEmitter.event().name("chat").data(noti));
System.out.println("채팅 여기");
emitter.send(SseEmitter.event().name("chat").data(noti));
System.out.println("채팅 여기");
// }
} else {
NotificationResponse noti = new NotificationResponse("team", redisRes.getData(), LocalDateTime.now());
// if (emitter != null) {
emitter.send(SseEmitter.event().name("team").data(noti));
System.out.println("팀 빌딩 여기");
emitter.send(SseEmitter.event().name("team").data(noti));
System.out.println("팀 빌딩 여기");
// }
}
} catch (IOException e) {
Expand All @@ -158,7 +157,7 @@ public void onMessage(Message message, byte[] pattern) {
}


//=================================================
//=================================================
// 로그아웃시 호출
public void completeEmitter() {
Long memberId = securityUtil.getCurrentMemberId();
Expand All @@ -173,7 +172,7 @@ public void completeEmitter() {
// type: chat
public void sendChatNotification(Long memberId, SseChatResponse sseChatResponse) {
SseEmitter emitter = clients.get(memberId);

if (emitter != null) {
publishMessage(new RedisRes("chat",sseChatResponse), memberId);
}
Expand Down Expand Up @@ -218,7 +217,7 @@ public void sendTeamBuild(Long memberId, SseTeamBuildResponse sseTeamBuildRespon


// if (emitter != null) {
sseRedisTemplate.convertAndSend(String.valueOf(memberId), new RedisRes("team",sseTeamBuildResponse));
sseRedisTemplate.convertAndSend(String.valueOf(memberId), new RedisRes("team",sseTeamBuildResponse));
// try {
// emitter.send(SseEmitter.event().name("team").data(noti));
// } catch (IOException e) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
spring:
profiles:
default: prod
default: local


0 comments on commit cb02e10

Please sign in to comment.