Skip to content

Commit

Permalink
YEL-88 [chore] 테스트를 위한 메세지큐 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
devkwonsehoon committed Aug 15, 2023
1 parent ca5767d commit 3d1a319
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.yello.server.infrastructure.rabbitmq.configuration;

import java.util.HashMap;
import java.util.Map;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
Expand Down Expand Up @@ -38,16 +40,19 @@ Queue votAvailableNotificationQueue() {
}

@Bean
TopicExchange topicExchange() {
return new TopicExchange(ExchangeName);
public CustomExchange delayedMessageExchange() {
Map<String, Object> args = new HashMap<>();
args.put("x-delayed-type", "direct");
return new CustomExchange(ExchangeName, "x-delayed-message", true, false, args);
}

@Bean
Binding votAvailableNotificationQueueQueueBinding(Queue voteAvailableNotificationQueue,
TopicExchange topicExchange) {
CustomExchange delayedMessageExchange) {
return BindingBuilder.bind(voteAvailableNotificationQueue)
.to(topicExchange)
.with("push.available");
.to(delayedMessageExchange)
.with("push.available")
.noargs();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ public void produceVoteAvailableNotification(Cooldown cooldown) {
"push.available",
voteAvailableQueueResponse,
message -> {
message.getMessageProperties()
.setHeader("x-delay", expiration);
message.getMessageProperties().setHeader("x-delay", expiration);
return message;
}
);
} catch (Exception exception) {
log.error(exception.getMessage());
}

log.info("[rabbitmq] produced message in queue");
}
}
}

0 comments on commit 3d1a319

Please sign in to comment.