package com.magamochi.image.queue.consumer; import com.magamochi.common.queue.command.ImageFetchCommand; import com.magamochi.common.queue.command.ImageUpdateCommand; import com.magamochi.image.queue.producer.ImageUpdateProducer; import com.magamochi.image.service.ImageFetchService; import lombok.RequiredArgsConstructor; import lombok.extern.log4j.Log4j2; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.stereotype.Service; @Log4j2 @Service @RequiredArgsConstructor public class ImageFetchConsumer { private final ImageFetchService imageFetchService; private final ImageUpdateProducer imageUpdateProducer; @RabbitListener(queues = "${queues.image-fetch}") public void receiveImageFetchCommand(ImageFetchCommand command) { log.info("Received image fetch command: {}", command); var imageId = imageFetchService.fetchImage(command.url(), command.contentType()); imageUpdateProducer.publishImageUpdateCommand( new ImageUpdateCommand(command.entityId(), imageId), command.contentType()); } }