-
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 #2 from gbzarelli/IMPLEMENT_MESSAGE_QUEUING_#1
Implement message queuing #1
- Loading branch information
Showing
13 changed files
with
160 additions
and
10 deletions.
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
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
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
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
33 changes: 33 additions & 0 deletions
33
src/main/java/br/com/beblue/musicstore/amq/SaleAMQSender.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,33 @@ | ||
package br.com.beblue.musicstore.amq; | ||
|
||
import org.springframework.amqp.AmqpException; | ||
import org.springframework.amqp.core.TopicExchange; | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static br.com.beblue.musicstore.util.BeanConst.BEAN_SALE_EXCHANGE; | ||
import static br.com.beblue.musicstore.util.ResourceConst.KEY_APPLICATION_MQ_SALE_ROUTING_KEY; | ||
|
||
@Component | ||
public class SaleAMQSender { | ||
|
||
@Value(KEY_APPLICATION_MQ_SALE_ROUTING_KEY) | ||
private String exchangeRoutingKey; | ||
|
||
private final RabbitTemplate rabbitTemplate; | ||
private final TopicExchange topicExchange; | ||
|
||
@Autowired | ||
public SaleAMQSender(RabbitTemplate rabbitTemplate, @Qualifier(BEAN_SALE_EXCHANGE) TopicExchange topicExchange) { | ||
this.rabbitTemplate = rabbitTemplate; | ||
this.topicExchange = topicExchange; | ||
} | ||
|
||
public void send(String order) throws AmqpException { | ||
rabbitTemplate.convertAndSend(topicExchange.getName(), exchangeRoutingKey, order); | ||
} | ||
|
||
} |
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
46 changes: 46 additions & 0 deletions
46
src/main/java/br/com/beblue/musicstore/settings/amq/SaleConfig.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 br.com.beblue.musicstore.settings.amq; | ||
|
||
import org.springframework.amqp.core.Binding; | ||
import org.springframework.amqp.core.BindingBuilder; | ||
import org.springframework.amqp.core.Queue; | ||
import org.springframework.amqp.core.TopicExchange; | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.DependsOn; | ||
|
||
import static br.com.beblue.musicstore.util.BeanConst.BEAN_SALE_QUEUE; | ||
import static br.com.beblue.musicstore.util.BeanConst.BEAN_SALE_EXCHANGE; | ||
import static br.com.beblue.musicstore.util.ResourceConst.*; | ||
|
||
@Configuration | ||
public class SaleConfig { | ||
|
||
@Value(KEY_APPLICATION_MQ_SALE_QUEUE_NAME) | ||
private String queueName; | ||
|
||
@Value(KEY_APPLICATION_MQ_SALE_EXCHANGE_NAME) | ||
private String exchangeName; | ||
|
||
@Value(KEY_APPLICATION_MQ_SALE_ROUTING_KEY) | ||
private String exchangeRoutingKey; | ||
|
||
@Bean(BEAN_SALE_QUEUE) | ||
Queue queue() { | ||
return new Queue(queueName, true); | ||
} | ||
|
||
@Bean(BEAN_SALE_EXCHANGE) | ||
TopicExchange exchange() { | ||
return new TopicExchange(exchangeName); | ||
} | ||
|
||
@Bean | ||
@DependsOn({BEAN_SALE_QUEUE, BEAN_SALE_EXCHANGE}) | ||
Binding binding(@Qualifier(BEAN_SALE_QUEUE) Queue queue, @Qualifier(BEAN_SALE_EXCHANGE) TopicExchange exchange) { | ||
return BindingBuilder.bind(queue).to(exchange).with(exchangeRoutingKey); | ||
} | ||
|
||
} |
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
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,6 @@ | ||
package br.com.beblue.musicstore.util; | ||
|
||
public class BeanConst { | ||
public static final String BEAN_SALE_QUEUE = "saleQueue"; | ||
public static final String BEAN_SALE_EXCHANGE = "saleExchange"; | ||
} |
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
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 |
---|---|---|
|
@@ -13,4 +13,7 @@ spring: | |
jpa: | ||
properties: | ||
hibernate: | ||
show_sql: false | ||
show_sql: false | ||
|
||
rabbitmq: | ||
host: rabbitmq |
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
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