-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from kusitms-28th-Meetup-E/feat/rabbit
feat : rabbitMQ
- Loading branch information
Showing
3 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/gwangjang/server/global/rabbitMQ/RabbitMQConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
src/main/java/gwangjang/server/global/rabbitMQ/Receiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} |