Skip to content

Commit

Permalink
Merge pull request #31 from kusitms-28th-Meetup-E/feat/rabbit
Browse files Browse the repository at this point in the history
feat : rabbitMQ
  • Loading branch information
eojinny authored Nov 23, 2023
2 parents 7b867d7 + 3966ca0 commit 5be9f6c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ dependencies {
implementation group: 'org.springframework.cloud', name: 'spring-cloud-stream-binder-kafka', version: '3.2.1'



implementation 'org.springframework.boot:spring-boot-starter-amqp'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.amqp:spring-rabbit-test'
implementation 'org.springframework.boot:spring-boot-starter-amqp:2.5.4'

}

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/gwangjang/server/global/rabbitMQ/RabbitMQConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package gwangjang.server.global.rabbitMQ;

import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

@Bean
public TopicExchange topic() {
return new TopicExchange("amq.topic");
}

@Bean
public Jackson2JsonMessageConverter producerJackson2MessageConverter() {
return new Jackson2JsonMessageConverter();
}

@Bean
public RabbitTemplate rabbitTemplate(final ConnectionFactory connectionFactory) {
final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setMessageConverter(producerJackson2MessageConverter());
return rabbitTemplate;
}
}
31 changes: 31 additions & 0 deletions src/main/java/gwangjang/server/global/rabbitMQ/Receiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package gwangjang.server.global.rabbitMQ;


import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.concurrent.CountDownLatch;

@Component
public class Receiver {

@RabbitListener(bindings = @QueueBinding(
value = @Queue,
exchange = @Exchange(value = "amq.topic", type = "topic", durable = "true"), //
key = "test"))
public void handleMsg1() {
System.out.println("test");
}

@RabbitListener(bindings = @QueueBinding(
value = @Queue(value = "kkaok", durable = "true"),
exchange = @Exchange(value = "amq.topic", type = "topic", durable = "true"), //
key = "test.0001"))
public void handleMsg2() {
System.out.println("test");
}

}

0 comments on commit 5be9f6c

Please sign in to comment.