From b608b632ecbbfeef4fc127a0654806a4dab881c6 Mon Sep 17 00:00:00 2001 From: JunYong Sun Date: Sat, 20 Jan 2024 13:22:49 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20LocalDynamodb=20config=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuctionServiceApplication.java | 51 ------------- .../config/LocalDynamoConfig.java | 71 +++++++++++++++++++ .../controller/ChatHandler.java | 20 ------ 3 files changed, 71 insertions(+), 71 deletions(-) create mode 100644 src/main/java/com/dailyon/auctionservice/config/LocalDynamoConfig.java diff --git a/src/main/java/com/dailyon/auctionservice/AuctionServiceApplication.java b/src/main/java/com/dailyon/auctionservice/AuctionServiceApplication.java index fc7d323..f4d7ba6 100644 --- a/src/main/java/com/dailyon/auctionservice/AuctionServiceApplication.java +++ b/src/main/java/com/dailyon/auctionservice/AuctionServiceApplication.java @@ -1,32 +1,17 @@ package com.dailyon.auctionservice; -import com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsync; -import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; -import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; -import com.amazonaws.services.dynamodbv2.model.Projection; -import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput; -import com.amazonaws.services.dynamodbv2.util.TableUtils; -import com.dailyon.auctionservice.document.Auction; -import com.dailyon.auctionservice.document.AuctionHistory; -import com.dailyon.auctionservice.document.BidHistory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; -import org.springframework.context.annotation.Profile; import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; import java.util.TimeZone; @EnableFeignClients @EnableDiscoveryClient @SpringBootApplication public class AuctionServiceApplication { - @Autowired AmazonDynamoDBAsync dynamoDB; - - @Autowired DynamoDBMapper dynamoDBMapper; public static void main(String[] args) { SpringApplication.run(AuctionServiceApplication.class, args); @@ -36,40 +21,4 @@ public static void main(String[] args) { public void setTimezoneToSeoul() { TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul")); } - - // TODO : document FIX 후 삭제 - @PostConstruct - @Profile({"!test"}) - public void setDynamoDB() { - CreateTableRequest createAuction = - dynamoDBMapper - .generateCreateTableRequest(Auction.class) - .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L)); - - CreateTableRequest createBidHistory = - dynamoDBMapper - .generateCreateTableRequest(BidHistory.class) - .withProvisionedThroughput(new ProvisionedThroughput(100L, 100L)); - - CreateTableRequest createAuctionHistory = - dynamoDBMapper - .generateCreateTableRequest(AuctionHistory.class) - .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L)); - - createBidHistory - .getGlobalSecondaryIndexes() - .forEach( - idx -> - idx.withProvisionedThroughput(new ProvisionedThroughput(1000L, 1000L)) - .withProjection(new Projection().withProjectionType("ALL"))); - createAuctionHistory - .getGlobalSecondaryIndexes() - .forEach( - idx -> - idx.withProvisionedThroughput(new ProvisionedThroughput(1L, 1L)) - .withProjection(new Projection().withProjectionType("ALL"))); - TableUtils.createTableIfNotExists(dynamoDB, createAuction); - TableUtils.createTableIfNotExists(dynamoDB, createBidHistory); - TableUtils.createTableIfNotExists(dynamoDB, createAuctionHistory); - } } diff --git a/src/main/java/com/dailyon/auctionservice/config/LocalDynamoConfig.java b/src/main/java/com/dailyon/auctionservice/config/LocalDynamoConfig.java new file mode 100644 index 0000000..c47d487 --- /dev/null +++ b/src/main/java/com/dailyon/auctionservice/config/LocalDynamoConfig.java @@ -0,0 +1,71 @@ +package com.dailyon.auctionservice.config; + +import com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsync; +import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; +import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; +import com.amazonaws.services.dynamodbv2.model.Projection; +import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput; +import com.amazonaws.services.dynamodbv2.util.TableUtils; +import com.dailyon.auctionservice.document.Auction; +import com.dailyon.auctionservice.document.AuctionHistory; +import com.dailyon.auctionservice.document.BidHistory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +@Configuration +@Profile({"local"}) +public class LocalDynamoConfig { + + @Autowired AmazonDynamoDBAsync dynamoDB; + + @Autowired DynamoDBMapper dynamoDBMapper; + + @PostConstruct + @Profile({"!test"}) + public void setDynamoDB() { + CreateTableRequest createAuction = + dynamoDBMapper + .generateCreateTableRequest(Auction.class) + .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L)); + + CreateTableRequest createBidHistory = + dynamoDBMapper + .generateCreateTableRequest(BidHistory.class) + .withProvisionedThroughput(new ProvisionedThroughput(100L, 100L)); + + CreateTableRequest createAuctionHistory = + dynamoDBMapper + .generateCreateTableRequest(AuctionHistory.class) + .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L)); + + createBidHistory + .getGlobalSecondaryIndexes() + .forEach( + idx -> + idx.withProvisionedThroughput(new ProvisionedThroughput(1000L, 1000L)) + .withProjection(new Projection().withProjectionType("ALL"))); + createAuctionHistory + .getGlobalSecondaryIndexes() + .forEach( + idx -> + idx.withProvisionedThroughput(new ProvisionedThroughput(1L, 1L)) + .withProjection(new Projection().withProjectionType("ALL"))); + TableUtils.createTableIfNotExists(dynamoDB, createAuction); + TableUtils.createTableIfNotExists(dynamoDB, createBidHistory); + TableUtils.createTableIfNotExists(dynamoDB, createAuctionHistory); + } + + @PreDestroy + public void deleteDynamoDB() { + TableUtils.deleteTableIfExists( + dynamoDB, dynamoDBMapper.generateDeleteTableRequest(AuctionHistory.class)); + TableUtils.deleteTableIfExists( + dynamoDB, dynamoDBMapper.generateDeleteTableRequest(Auction.class)); + TableUtils.deleteTableIfExists( + dynamoDB, dynamoDBMapper.generateDeleteTableRequest(BidHistory.class)); + } +} diff --git a/src/main/java/com/dailyon/auctionservice/controller/ChatHandler.java b/src/main/java/com/dailyon/auctionservice/controller/ChatHandler.java index e8dcb45..1abe948 100644 --- a/src/main/java/com/dailyon/auctionservice/controller/ChatHandler.java +++ b/src/main/java/com/dailyon/auctionservice/controller/ChatHandler.java @@ -5,7 +5,6 @@ import com.dailyon.auctionservice.chat.util.ObjectStringConverter; import com.dailyon.auctionservice.dto.request.Message; import lombok.extern.slf4j.Slf4j; -import org.springframework.util.StringUtils; import org.springframework.web.reactive.socket.WebSocketHandler; import org.springframework.web.reactive.socket.WebSocketMessage; import org.springframework.web.reactive.socket.WebSocketSession; @@ -13,10 +12,6 @@ import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - import static com.dailyon.auctionservice.chat.response.ChatCommand.MESSAGE; @Slf4j @@ -71,21 +66,6 @@ public Mono handle(WebSocketSession session) { return Mono.zip(inputMessage, outputMessage).then(); } - private Map getQueryMap(String queryStr) { - Map queryMap = new HashMap<>(); - if (!StringUtils.isEmpty(queryStr)) { - String[] queryParam = queryStr.split("&"); - Arrays.stream(queryParam) - .forEach( - s -> { - String[] kv = s.split("=", 2); - String value = kv.length == 2 ? kv[1] : ""; - queryMap.put(kv[0], value); - }); - } - return queryMap; - } - public Mono sendMessage(ChatPayload chatMessage) { return Mono.fromSupplier(() -> chatMessageSink.tryEmitNext(chatMessage)) .doOnSuccess(