Skip to content

Commit

Permalink
[FIX] LocalDynamodb config 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ssjy4974 committed Jan 20, 2024
1 parent 26b2f51 commit b608b63
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@
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;
import reactor.core.publisher.Flux;
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
Expand Down Expand Up @@ -71,21 +66,6 @@ public Mono<Void> handle(WebSocketSession session) {
return Mono.zip(inputMessage, outputMessage).then();
}

private Map<String, String> getQueryMap(String queryStr) {
Map<String, String> 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<Sinks.EmitResult> sendMessage(ChatPayload chatMessage) {
return Mono.fromSupplier(() -> chatMessageSink.tryEmitNext(chatMessage))
.doOnSuccess(
Expand Down

0 comments on commit b608b63

Please sign in to comment.