diff --git a/ranking/src/main/java/youthfi/ranking/config/TopologyConfig.java b/ranking/src/main/java/youthfi/ranking/config/TopologyConfig.java index 6a8369b..d9554ec 100644 --- a/ranking/src/main/java/youthfi/ranking/config/TopologyConfig.java +++ b/ranking/src/main/java/youthfi/ranking/config/TopologyConfig.java @@ -37,24 +37,15 @@ public KStream kStream(StreamsBuilder builder) { .filter((k,v) -> v != null) .selectKey((k,v) -> v.getUserId() + "|" + v.getStockId()); - // ★ 3파티션 강제 - KStream execP3 = execStream.repartition( - Repartitioned.as("exec-p3") - .withNumberOfPartitions(3) - .withKeySerde(Serdes.String()) - .withValueSerde(executionSerde()) - ); - - // 1) BUY 롯 상태 스토어 + // 1) BUY 롯 상태 스토어 (키=userId|stockId, 값=Deque 직렬화 바이트) var lotsStoreBuilder = Stores.keyValueStoreBuilder( Stores.persistentKeyValueStore("buy-lots"), Serdes.String(), Serdes.ByteArray()); builder.addStateStore(lotsStoreBuilder); // 2) FIFO 처리 → SELL 시 실현 수익률(Double) 방출 - // ★ execP3 사용 KStream realizedRatePerTrade = - execP3.transformValues( + execStream.transformValues( () -> new RealizedRateFifoTransformer("buy-lots"), "buy-lots" ).filter((k,v) -> v != null); @@ -69,22 +60,14 @@ public KStream kStream(StreamsBuilder builder) { .withValueSerde(Serdes.Double()) ); - // ★ top10 앞단 3파티션 보장 - KStream ratesP3 = userLatestRate.toStream().repartition( - Repartitioned.as("rates-p3") - .withNumberOfPartitions(3) - .withKeySerde(Serdes.String()) - .withValueSerde(Serdes.Double()) - ); - // 4) Top10 계산 (StateStore) var topStoreBuilder = Stores.keyValueStoreBuilder( Stores.persistentKeyValueStore("top10-store"), Serdes.String(), Serdes.Double()); builder.addStateStore(topStoreBuilder); - // ★ ratesP3 사용 - KStream> top10 = ratesP3 + KStream> top10 = userLatestRate + .toStream() .transformValues(() -> new TopNTransformer("top10-store"), "top10-store"); // 5) JSON 직렬화 후 발행 @@ -125,4 +108,4 @@ private Serde executionSerde() { }; return Serdes.serdeFrom(ser, de); } -} +} \ No newline at end of file diff --git a/ranking/src/main/resources/application.yaml b/ranking/src/main/resources/application.yaml index 2867229..15f8e3e 100644 --- a/ranking/src/main/resources/application.yaml +++ b/ranking/src/main/resources/application.yaml @@ -11,7 +11,7 @@ spring: username="${KAFKA_USERNAME}" password="${KAFKA_PASSWORD}"; streams: - application-id: profit-ranking-app + application-id: profit-ranking-app-v2 state-dir: /tmp/kafka-streams replication-factor: 1 properties: @@ -21,6 +21,5 @@ spring: processing.guarantee: exactly_once_v2 topics: - userstock: finance.finance.userstock execution: finance.finance.execution out: notify.ranking.top10