-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ContentProducer & SummarizedContentConsumer 구현
ContentProducer, SummarizedContentConsumer, ContentMessageDto
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
backend/src/main/java/com/rollthedice/backend/domain/news/contentqueue/ContentProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.rollthedice.backend.domain.news.contentqueue; | ||
|
||
import com.rollthedice.backend.domain.news.dto.ContentMessageDto; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Component | ||
public class ContentProducer { | ||
@Value("${rabbitmq.summary.exchange.name}") | ||
private String exchangeName; | ||
|
||
@Value("${rabbitmq.summary.routing.key}") | ||
private String routingKey; | ||
|
||
private final RabbitTemplate rabbitTemplate; | ||
|
||
public void sendMessage(ContentMessageDto messageDto) { | ||
log.info("publish news content message : {}", messageDto.getId()); | ||
rabbitTemplate.convertAndSend(exchangeName, routingKey, messageDto); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...main/java/com/rollthedice/backend/domain/news/contentqueue/SummarizedContentConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.rollthedice.backend.domain.news.contentqueue; | ||
|
||
import com.rollthedice.backend.domain.news.dto.ContentMessageDto; | ||
import com.rollthedice.backend.domain.news.service.NewsService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Component | ||
public class SummarizedContentConsumer { | ||
private final NewsService newsService; | ||
|
||
@RabbitListener(queues = "${rabbitmq.store.queue.name}") | ||
public void receiveMessage(ContentMessageDto messageDto) { | ||
log.info("Received summarized news message id: {}", messageDto.getId()); | ||
newsService.updateSummarizedNews(messageDto); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/com/rollthedice/backend/domain/news/dto/ContentMessageDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.rollthedice.backend.domain.news.dto; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ContentMessageDto { | ||
private Long id; | ||
private String content; | ||
} |