전체 글
-
Spring Batch로 대용량 데이터 처리 비동기화하기Spring 2024. 8. 5. 17:46
문제 상황Scoop이라는 프로젝트에 매일 오전 6시와 12시에 네이버 뉴스 기사를 크롤링하는 로직이 있다. 이때, 크롤링한 뉴스를 요약까지 해야했고, 요약에는 GPT API를 사용했다. 또한, 이러한 GPT API는 FastAPI에 구현하여, 다른 서버에 존재한다. 간단한 흐름은 다음과 같다. 1. 네이버 뉴스의 각 카테고리의 뉴스들의 URL을 크롤링한다.2. 크롤링한 뉴스 URL을 사용하여 뉴스 본문을 크롤링한다.3. 크롤링한 뉴스 본문 내용 메시지를 publish 한다.4. FastAPI 서버에서 해당 메시지를 consume하여 뉴스 내용을 요약한다.5. 요약된 뉴스 내용 메시지를 publish 한다.6. Spring 서버에서 메시지를 consume하여 요약된 뉴스 내용을 DB에 저장한다. 하지만 위..
-
[백준] 26093 고양이 목에 리본 달기 (DP)코딩 테스트 2024. 6. 26. 19:18
https://www.acmicpc.net/problem/26093 제목외로운 윤제는 고양이를 키우기로 했다. 𝑁 마리의 고양이를 입양하기로 한 윤제는 고양이들에게 리본을 달아주기 위해 𝐾 종류의 리본을 충분히 준비했다. 즉, 각 리본의 개수는 무한하다. 각 고양이마다 리본의 종류에 따라 좋아하는 정도가 다르고, 이를 만족도로 나타낼 수 있다. 고양이들을 번호순으로 한 줄로 세우고 리본을 달아주려고 하는데, 각 고양이는 자신과 이웃한(왼쪽 혹은 오른쪽) 고양이와 같은 종류의 리본을 다는 것을 굉장히 싫어한다. 윤제는 고양이들이 싫어하는 상황을 피하면서 각 고양이의 리본에 대한 만족도의 총합을 극대화하고 싶다. 이 조건을 만족하는 만족도 합의 최댓값을 윤제에게 알려주자. 입력첫 번째 줄에는 고양이의 수 𝑁..
-
[트러블 슈팅] @InjectMocks @Mock vs. @Autowired @MockBeanSpring 2024. 6. 17. 06:42
단위 테스트를 구현하다가 아래와 같은 오류를 만났다.com.rollthedice.backend.domain.news.exception.NewsNotFoundException: 뉴스를 찾지 못했습니다. at java.base/java.util.Optional.orElseThrow(Optional.java:403) at com.rollthedice.backend.domain.news.service.NewsService.getDetailNews(NewsService.java:75) at ⬇️ 오류 로그 전체더보기com.rollthedice.backend.domain.news.exception.NewsNotFoundException: 뉴스를 찾지 못했습니다. at java.base/java.util.Optio..
-
Github Actions + Git Submodule로 application.yml 관리하기Spring 2024. 4. 10. 04:19
Scoop 프로젝트를 하며 Spring의 application-dev.yml 코드의 여러 키값들을 공개하지 않아야 했다. 그래서 처음에 각 값들을 secrets에 저장해서 사용하는 방식을 선택했다. 그랬더니 아래와 같은 코드가.. 되었다. env: spring.datasource.driver-class-name: ${{ secrets.DRIVER_CLASS_NAME }} spring.datasource.url: ${{ secrets.DATASOURCE_URL }} spring.datasource.username: ${{ secrets.DATABASE_USERNAME }} spring.datasource.password: ${{ ..
-
RabbitMQ에 대하여Backend 2024. 3. 3. 17:17
RabbitMQ 서버간(Producers → Consumers) 메세지를 전달해주는 오픈소스 메세지 브로커 AMQP를 구현한 메세지 브로커 AMQP(Advanced Message Queuing Protocol) 인스턴스가 데이터를 서로 교환할 때 사용하는 방법 해당 프로토콜을 구현한 MQ제품들이 여러가지가 있으며, 그 중 하나가 RabbitMQ인 것 구성요소 Exchange Queue Binding 애플리케이션간 결합도를 낮출 수 있음 이럴 때 사용하면 좋다! 요청을 많은 사용자에게 전달할 때 요청에 대한 처리 시간이 길 때 많은 작업이 요청되어 처리를 해야할 때 → 나 같은 경우는 이번 프로젝트에서 크롤링과 gpt api를 사용해야 하는데, 요청 처리 시간이 길어 RabbitMQ 사용을 고려 중이다. ..
-
[Redis] Redis 이용하기Backend 2024. 1. 15. 17:08
mac에 redis를 설치해서 이용하는 방법은 뒤로 갈수록 까다로워지기 때문에 docker에 redis를 설치해서 사용할 것이다. 우선 Docker Desktop을 실행한다.그리고 docker hub에 접속해서 redis를 검색한다. Docker Official Image 라고 되어있는 redis를 클릭한다. 그럼 docker pull redis 를 Docker에 redis image를 pull하고 run 하는 방법이 네트워크로 두 개의 컨테이너를 연결하는 것보다 편하지만, redis-cli를 이용하기 위해서는 Docker에 redis 컨테이너와 local-redis 컨테이너를 network로 연결해줘야 한다. Redis Image pulldocker image pull redis Redis netwo..
-
[백준 2343번] 기타레슨코딩 테스트 2024. 1. 3. 17:42
get get get get a guitar 🎶 이진탐색 문제이다. 사실 실제 코딩테스트를 칠 때 이런 문제가 나오면 이진 탐색을 떠올릴 수 있을지 모르겠다.. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class B2343 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new S..
-
[Redis] Redis에 대하여Backend 2024. 1. 3. 00:49
🤔 Redis 란? Remote dictionary server (외부에 있는 dictionary라는 자료구조를 사용하는 서버) RDBMS와 같이 쿼리 연산을 지원하지 않음 인메모리 데이터베이스 빠른 속도 Key-Value 타입의 저장소 NoSQL로 분류됨 Remote Data Storage로 여러 서버에서 같은 데이터를 공유하고 보고 싶을 때 사용할 수 있음 쓰기 성능 증대를 위한 클라이언트 측 샤딩을 지원함 Sharding이란? 같은 테이블 스키마를 가진 데이터를 다수의 데이터베이스에 분산하여 저장하는 방법 스냅샷 기능을 제공하여 메모리 내용을 *.rdb 파일로 저장하여 해당 시점으로 복구 가능 다양한 자료구조를 가지고 있음 Hash List Set String Bitmap etc.. 🪡 Redis에..