Skip to content

Commit

Permalink
feat: implement web database downloader
Browse files Browse the repository at this point in the history
- 웹 데이터베이스 다운로드를 위한 컴포넌트 구현
  • Loading branch information
seokwns committed Jan 16, 2024
1 parent 2aa6bce commit 8ed3081
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,13 @@ public WebClient imageWebClient() {
throw new ServerException(ExceptionStatus.IMAGE_PARSING_ERROR);
}
}

@Bean(name = "databaseWebClient")
public WebClient databaseWebClient() {
return WebClient.builder()
.exchangeStrategies(ExchangeStrategies.builder()
.codecs(clientCodecConfigurer -> clientCodecConfigurer.defaultCodecs().maxInMemorySize(100 * 1024 * 1024))
.build())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.see.realview._core.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.List;

@Component
@Slf4j
public class WebDatabaseReader {

private final WebClient databaseWebClient;

public WebDatabaseReader(@Autowired @Qualifier("databaseWebClient") WebClient databaseWebClient) {
this.databaseWebClient = databaseWebClient;
}

public List<String> read(String url, String identifier) {
log.debug("웹 데이터베이스 다운로드 시작 | " + url);
Mono<byte[]> readBytes = databaseWebClient
.get()
.uri(url)
.retrieve()
.bodyToMono(byte[].class);

byte[] dataBytes = readBytes.block();
if (dataBytes == null) {
log.debug("웹 데이터베이스 다운로드 실패 | " + url);
return List.of();
}

log.debug("웹 데이터베이스 다운로드 완료 | " + url);
String data = Arrays.toString(dataBytes);
return List.of(data.split(identifier));
}
}

0 comments on commit 8ed3081

Please sign in to comment.