Skip to content

Commit

Permalink
feat: ContentProducer & SummarizedContentConsumer 구현
Browse files Browse the repository at this point in the history
ContentProducer, SummarizedContentConsumer, ContentMessageDto
  • Loading branch information
yeonjy committed Mar 18, 2024
1 parent 9edf6b5 commit 3975c95
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
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);
}
}
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);
}
}
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;
}

0 comments on commit 3975c95

Please sign in to comment.