-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of RabbitMQ, create sender and listener
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
customer-service/src/main/java/by/rom/customerservice/config/MessageConfig.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,46 @@ | ||
package by.rom.customerservice.config; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.amqp.core.*; | ||
import org.springframework.amqp.rabbit.connection.ConnectionFactory; | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; | ||
import org.springframework.amqp.support.converter.MessageConverter; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@Slf4j | ||
public class MessageConfig { | ||
|
||
public static final String QUEUE = "notification_queue"; | ||
public static final String EXCHANGE = "micro_exchange"; | ||
public static final String ROUTING_KEY = "routing_key"; | ||
|
||
@Bean | ||
public Queue queue(){ | ||
return new Queue(QUEUE); | ||
} | ||
|
||
@Bean | ||
public TopicExchange exchange(){ | ||
return new TopicExchange(EXCHANGE); | ||
} | ||
|
||
@Bean | ||
public Binding binding(Queue queue, TopicExchange topicExchange){ | ||
return BindingBuilder.bind(queue).to(topicExchange).with(ROUTING_KEY); | ||
} | ||
|
||
@Bean | ||
public MessageConverter converter(){ | ||
return new Jackson2JsonMessageConverter(); | ||
} | ||
|
||
@Bean | ||
public AmqpTemplate template(ConnectionFactory connectionFactory) { | ||
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory); | ||
rabbitTemplate.setMessageConverter(converter()); | ||
return rabbitTemplate; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
notification-service/src/main/java/by/rom/notificationservice/config/MessageConverter.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,14 @@ | ||
package by.rom.notificationservice.config; | ||
|
||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class MessageConverter { | ||
|
||
@Bean | ||
public org.springframework.amqp.support.converter.MessageConverter converter(){ | ||
return new Jackson2JsonMessageConverter(); | ||
} | ||
} |
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