Skip to content

Commit

Permalink
fix: aop 제거 (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
yonghwankim-dev authored Sep 24, 2024
1 parent 509a687 commit b838e50
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 56 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import org.springframework.web.socket.client.WebSocketClient;

import co.fineants.api.domain.kis.properties.KisProperties;
import co.fineants.price.domain.stockprice.aop.RequiredWebSocketApprovalKey;
import co.fineants.api.domain.kis.repository.WebSocketApprovalKeyRedisRepository;
import co.fineants.api.domain.kis.service.KisService;
import co.fineants.price.domain.stockprice.factory.StockPriceWebSocketMessageFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -29,6 +30,8 @@ public class StockPriceWebSocketClient {
private final ApplicationEventPublisher eventPublisher;
private final KisProperties kisProperties;
private final StockPriceWebSocketMessageFactory factory;
private final WebSocketApprovalKeyRedisRepository repository;
private final KisService kisService;
@Value("${kis.websocket.auto-connect:true}")
private boolean websocketAutoConnect;
private WebSocketSession session = null;
Expand All @@ -41,8 +44,8 @@ private void init() {
connect(kisProperties.getWebsocketCurrentPriceUrl());
}

@RequiredWebSocketApprovalKey
public void connect(@NotNull String url) {
checkWebSocketApprovalKey();
try {
session = webSocketClient.execute(stockPriceWebSocketHandler, url).get();
log.info("connect Session : {}, uri : {}", session, url);
Expand All @@ -56,6 +59,16 @@ public void connect(@NotNull String url) {
}
}

private void checkWebSocketApprovalKey() {
repository.fetchApprovalKey().ifPresentOrElse(
approvalKey -> log.info("Approval key already exists: {}", approvalKey),
() -> {
kisService.fetchApprovalKey().ifPresent(repository::saveApprovalKey);
log.info("Approval key fetched and saved");
}
);
}

public boolean sendSubscribeMessage(String ticker) {
return sendMessage(ticker, factory.currentPriceSubscribeMessage(ticker));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,11 @@ public void handleMessage(@NotNull WebSocketSession session, WebSocketMessage<?>
handleStockTextMessage(payload);
} else if (isPingPongMessage(payload)) {
sendPongMessage(session, message);
} else if (isSubscribeInternalErrorMessage(payload) || isMaxSubscribeOverMessage(payload)) {
log.info("Received Message : {}", message.getPayload());
} else {
log.info("Received Message : {}", message.getPayload());
}
}

private boolean isMaxSubscribeOverMessage(String payload) {
return payload.contains("MAX SUBSCRIBE OVER");
}

private boolean isSubscribeInternalErrorMessage(@NotNull String payload) {
return payload.contains("SUBSCRIBE INTERNAL ERROR");
}

private boolean isPingPongMessage(@NotNull String message) {
return message.contains("PINGPONG");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.web.socket.client.WebSocketClient;
import org.springframework.web.socket.client.standard.StandardWebSocketClient;

@EnableAspectJAutoProxy
@Configuration
public class StockPriceConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import co.fineants.api.domain.kis.properties.KisProperties;
import co.fineants.api.domain.kis.repository.CurrentPriceRedisRepository;
import co.fineants.api.domain.kis.repository.WebSocketApprovalKeyRedisRepository;
import co.fineants.api.domain.kis.service.KisService;
import co.fineants.price.domain.stockprice.factory.StockPriceWebSocketMessageFactory;

class StockPriceWebSocketClientTest extends AbstractContainerBaseTest {
Expand All @@ -52,6 +53,9 @@ class StockPriceWebSocketClientTest extends AbstractContainerBaseTest {
@Autowired
private StockPriceWebSocketMessageFactory factory;

@Autowired
private KisService kisService;

@LocalServerPort
private int port;

Expand Down Expand Up @@ -89,7 +93,7 @@ void sendMessage_whenBrokenPipe_thenCloseAndReconnectSession() throws IOExceptio
BDDMockito.willThrow(new IOException("broken pipe"))
.given(session).sendMessage(ArgumentMatchers.any(WebSocketMessage.class));
StockPriceWebSocketClient stockPriceWebSocketClient = new StockPriceWebSocketClient(handler, webSocketClient,
eventPublisher, kisProperties, factory);
eventPublisher, kisProperties, factory, webSocketApprovalKeyRedisRepository, kisService);
stockPriceWebSocketClient.connect(url);

String ticker = "005930";
Expand Down Expand Up @@ -137,7 +141,7 @@ void disconnect_whenSessionFailClose_thenSessionIsNull() throws IOException {
.given(session).close(CloseStatus.NORMAL);

StockPriceWebSocketClient stockPriceWebSocketClient = new StockPriceWebSocketClient(handler, webSocketClient,
eventPublisher, kisProperties, factory);
eventPublisher, kisProperties, factory, webSocketApprovalKeyRedisRepository, kisService);
stockPriceWebSocketClient.connect(url);

// when
Expand Down

0 comments on commit b838e50

Please sign in to comment.