authorUuidList = subscribeRepository.findByAuthorUuid(kafkaFeedRequestDto.getUuid()); List receiverUuidList = authorUuidList .stream() .map(Subscribe::getSubscriberUuid) .toList(); String splitedContent = kafkaFeedRequestDto.getContent().length() > 20 ? kafkaFeedRequestDto.getContent().substring(0, 20) + "..." : kafkaFeedRequestDto.getContent(); //AlarmKafkaRequestDto kafkaAlarmRequestDto = AlarmKafkaRequestDto.toDto(kafkaFeedRequestDto, receiverUuidList, splitedContent, TYPE); NotificationKafkaRequestDto notificationKafkaRequestDto = NotificationKafkaRequestDto.toDto(kafkaFeedRequestDto, receiverUuidList, splitedContent, TYPE); sendMessage("feed-create-join-sub"> authorUuidList = subscribeRepository.findByAuthorUuid(kafkaFeedRequestDto.getUuid()); List receiverUuidList = authorUuidList .stream() .map(Subscribe::getSubscriberUuid) .toList(); String splitedContent = kafkaFeedRequestDto.getContent().length() > 20 ? kafkaFeedRequestDto.getContent().substring(0, 20) + "..." : kafkaFeedRequestDto.getContent(); //AlarmKafkaRequestDto kafkaAlarmRequestDto = AlarmKafkaRequestDto.toDto(kafkaFeedRequestDto, receiverUuidList, splitedContent, TYPE); NotificationKafkaRequestDto notificationKafkaRequestDto = NotificationKafkaRequestDto.toDto(kafkaFeedRequestDto, receiverUuidList, splitedContent, TYPE); sendMessage("feed-create-join-sub"> authorUuidList = subscribeRepository.findByAuthorUuid(kafkaFeedRequestDto.getUuid()); List receiverUuidList = authorUuidList .stream() .map(Subscribe::getSubscriberUuid) .toList(); String splitedContent = kafkaFeedRequestDto.getContent().length() > 20 ? kafkaFeedRequestDto.getContent().substring(0, 20) + "..." : kafkaFeedRequestDto.getContent(); //AlarmKafkaRequestDto kafkaAlarmRequestDto = AlarmKafkaRequestDto.toDto(kafkaFeedRequestDto, receiverUuidList, splitedContent, TYPE); NotificationKafkaRequestDto notificationKafkaRequestDto = NotificationKafkaRequestDto.toDto(kafkaFeedRequestDto, receiverUuidList, splitedContent, TYPE); sendMessage("feed-create-join-sub">
@KafkaListener(topics = "feed-create"
		, groupId = "feed-join-subscribe"
		, containerFactory = "feedEventListenerContainerFactory")
	public void consumeFeedEvent(FeedKafkaRequestDto kafkaFeedRequestDto) {

		log.info("consumeFeedEvent: {}", kafkaFeedRequestDto.getContent());

		List<Subscribe> authorUuidList = subscribeRepository.findByAuthorUuid(kafkaFeedRequestDto.getUuid());

		List<String> receiverUuidList = authorUuidList
			.stream()
			.map(Subscribe::getSubscriberUuid)
			.toList();

		String splitedContent = kafkaFeedRequestDto.getContent().length() > 20 ? kafkaFeedRequestDto.getContent().substring(0, 20) + "..." : kafkaFeedRequestDto.getContent();

		//AlarmKafkaRequestDto kafkaAlarmRequestDto = AlarmKafkaRequestDto.toDto(kafkaFeedRequestDto, receiverUuidList, splitedContent, TYPE);
		NotificationKafkaRequestDto notificationKafkaRequestDto = NotificationKafkaRequestDto.toDto(kafkaFeedRequestDto, receiverUuidList,
			splitedContent, TYPE);
		sendMessage("feed-create-join-subscribe", notificationKafkaRequestDto);
	}

	public void sendMessage(String topic, NotificationKafkaRequestDto kafkaAlarmRequestDto) {
		kafkaTemplate.send(topic, kafkaAlarmRequestDto);
	}
  • feed 서비스의 consumer 역할을 하는 구독 service에서 feed 작성자의 정보에 그 feed 작성자에 대하여 게시글 알람 신청을 한 user들에 대한 정보를 통합

  • 통합된 정보를 다시 한번 kafka 메세지로 notification(알림) 서비스에 정보를 보내는 producer 역할을 하도록 설정

  • 보내는 topic은 “feed-create-join-subscribe”

  • 보내는 정보는

@Getter
@NoArgsConstructor
public class NotificationKafkaRequestDto {
	private String senderUuid;
	private List<String> receiverUuidList;
	private String content;
	private String mediaUrl;
	private String type;

	@Builder
	public NotificationKafkaRequestDto(
		String senderUuid,
		List<String> receiverUuidList,
		String content,
		String mediaUrl,
		String type
	) {
		this.senderUuid = senderUuid;
		this.receiverUuidList = receiverUuidList;
		this.content = content;
		this.mediaUrl = mediaUrl;
		this.type = type;
	}

	public static NotificationKafkaRequestDto toDto(FeedKafkaRequestDto kafkaFeedRequestDto, List<String> receiverUuidList, String splitedContent, String type) {
		return NotificationKafkaRequestDto.builder()
			.senderUuid(kafkaFeedRequestDto.getUuid())
			.receiverUuidList(receiverUuidList)
			.content(splitedContent)
			.mediaUrl(kafkaFeedRequestDto.getMediaUrlList().get(0))
			.type(type)
			.build();

	}
}
  • 미디어에 대한 정보를 넘기고 있으나 현재 notification service에서는 미디어를 따로 받지는 않음

    ← type 정보를 통하여 분기 처리

    • Listener에서 여러값들을 다양하게(sender, receiver, content, type, media(?)) 받을 수 있는 dto를 생성하여 파라미터로 설정 → type 값을 통하여 더 많은 정보를 가지고 있는 type 값이면 mongoDB에 알맞게 저장하고 정보를 최종 전달할 수 있도록 처리가 필요