diff --git a/src/main/java/com/yello/server/infrastructure/rabbitmq/repository/MessageQueueRabbitRepository.java b/src/main/java/com/yello/server/infrastructure/rabbitmq/repository/MessageQueueRabbitRepository.java index 99d2919b..bfb56493 100644 --- a/src/main/java/com/yello/server/infrastructure/rabbitmq/repository/MessageQueueRabbitRepository.java +++ b/src/main/java/com/yello/server/infrastructure/rabbitmq/repository/MessageQueueRabbitRepository.java @@ -8,11 +8,13 @@ import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeoutException; import lombok.RequiredArgsConstructor; +import lombok.extern.log4j.Log4j2; import org.springframework.amqp.core.MessagePostProcessor; import org.springframework.amqp.rabbit.connection.Connection; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.stereotype.Repository; +@Log4j2 @Repository @RequiredArgsConstructor public class MessageQueueRabbitRepository implements MessageQueueRepository { @@ -38,15 +40,18 @@ public void deleteMessageByMessageId(String messageId) throws IOException, Timeo long deliveryTag = getDeliveryTagByMessageId(channel, messageId); if (deliveryTag!=-1) { - channel.basicCancel(String.valueOf(deliveryTag)); + channel.basicAck(deliveryTag, false); + log.info("[rabbitmq] Successfully delete message %d !".formatted(deliveryTag)); } } } private long getDeliveryTagByMessageId(Channel channel, String messageId) throws IOException { GetResponse response = channel.basicGet("vote-available-notification-queue", false); + log.info("[rabbitmq] Successfully get channel %s".formatted(response.getEnvelope().getExchange())); while (response!=null) { + log.info("[rabbitmq] Searching message for remove ..."); String messageBody = new String(response.getBody(), StandardCharsets.UTF_8); ObjectMapper objectMapper = new ObjectMapper(); @@ -54,6 +59,7 @@ private long getDeliveryTagByMessageId(Channel channel, String messageId) throws VoteAvailableQueueResponse.class); if (voteAvailableQueueResponse.messageId().equals(messageId)) { + log.info("[rabbitmq] find message: %d".formatted(response.getEnvelope().getDeliveryTag())); return response.getEnvelope().getDeliveryTag(); } diff --git a/src/main/java/com/yello/server/infrastructure/rabbitmq/service/ConsumerRabbitmqService.java b/src/main/java/com/yello/server/infrastructure/rabbitmq/service/ConsumerRabbitmqService.java index 3b306e36..7c570945 100644 --- a/src/main/java/com/yello/server/infrastructure/rabbitmq/service/ConsumerRabbitmqService.java +++ b/src/main/java/com/yello/server/infrastructure/rabbitmq/service/ConsumerRabbitmqService.java @@ -34,6 +34,9 @@ public void consumeVoteAvailableNotification(final Message message) throws IOExc boolean exists = cooldownRepository.existsByUserId(voteAvailableQueueResponse.receiverId()); if (exists) { notificationService.sendVoteAvailableNotification(voteAvailableQueueResponse.receiverId()); + log.info("[rabbitmq] Successfully consume message %d".formatted( + message.getMessageProperties().getDeliveryTag()) + ); } } catch (Exception exception) { log.error("[rabbitmq] %s".formatted(exception.getMessage())); diff --git a/src/main/java/com/yello/server/infrastructure/rabbitmq/service/ProducerRabbitmqService.java b/src/main/java/com/yello/server/infrastructure/rabbitmq/service/ProducerRabbitmqService.java index 3cf5b923..05864ffd 100644 --- a/src/main/java/com/yello/server/infrastructure/rabbitmq/service/ProducerRabbitmqService.java +++ b/src/main/java/com/yello/server/infrastructure/rabbitmq/service/ProducerRabbitmqService.java @@ -36,6 +36,7 @@ public void produceVoteAvailableNotification(Cooldown cooldown) { return message; } ); + log.info("[rabbitmq] Successfully produce message. Cooldown [%s]".formatted(cooldown.getMessageId())); } catch (Exception exception) { log.error("[rabbitmq] %s".formatted(exception.getMessage())); }