Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : rabbitMQ #31

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}

}