优惠券+异常全局处理
This commit is contained in:
@@ -29,7 +29,7 @@ import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RabbitListener(queues = {RabbitConstants.CART_QUEUE_PUT})
|
||||
//@RabbitListener(queues = {RabbitConstants.CART_QUEUE_PUT})
|
||||
@Service
|
||||
public class CartConsumer {
|
||||
|
||||
@@ -39,6 +39,7 @@ public class CartConsumer {
|
||||
@Autowired
|
||||
private CartService cartService;
|
||||
@RabbitHandler
|
||||
@RabbitListener(queues = {"${queue}"})
|
||||
public void listener(String message) {
|
||||
try {
|
||||
JSONObject jsonObject = JSON.parseObject(message);
|
||||
|
||||
@@ -27,7 +27,8 @@ public class RabbitConfig {
|
||||
|
||||
@Value("${spring.rabbitmq.password}")
|
||||
private String password;
|
||||
|
||||
@Value("${prod}")
|
||||
private String prod;
|
||||
|
||||
|
||||
@Bean
|
||||
@@ -49,17 +50,17 @@ public class RabbitConfig {
|
||||
}
|
||||
@Bean
|
||||
public DirectExchange defaultExchange_Register() {
|
||||
return new DirectExchange(RabbitConstants.CART_PUT);
|
||||
return new DirectExchange(RabbitConstants.CART_PUT+prod);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue queuePut_Register() {
|
||||
return new Queue(RabbitConstants.CART_QUEUE_PUT, true); //队列持久
|
||||
return new Queue(RabbitConstants.CART_QUEUE_PUT+prod, true); //队列持久
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding bindingPut_Register() {
|
||||
return BindingBuilder.bind(queuePut_Register()).to(defaultExchange_Register()).with(RabbitConstants.CART_ROUTINGKEY_PUT);
|
||||
return BindingBuilder.bind(queuePut_Register()).to(defaultExchange_Register()).with(RabbitConstants.CART_ROUTINGKEY_PUT+prod);
|
||||
}
|
||||
@Bean
|
||||
public DirectExchange defaultIntegral() {
|
||||
|
||||
@@ -32,10 +32,10 @@ public interface RabbitConstants {
|
||||
|
||||
|
||||
|
||||
public static final String INTEGRAL_PUT="integral_put";
|
||||
public static final String INTEGRAL_PUT="integral_put1";
|
||||
|
||||
public static final String INTEGRAL_QUEUE_PUT = "integral_queue_put";
|
||||
public static final String INTEGRAL_QUEUE_PUT = "integral_queue_put1";
|
||||
|
||||
|
||||
public static final String INTEGRAL_ROUTINGKEY_PUT = "integral_routingkey_put";
|
||||
public static final String INTEGRAL_ROUTINGKEY_PUT = "integral_routingkey_put1";
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@@ -16,7 +17,8 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Value("${prod}")
|
||||
private String prod;
|
||||
@Autowired
|
||||
public RabbitProducer(RabbitTemplate rabbitTemplate) {
|
||||
this.rabbitTemplate = rabbitTemplate;
|
||||
@@ -25,7 +27,7 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback {
|
||||
|
||||
public void putCart(String content) {
|
||||
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.CART_PUT, RabbitConstants.CART_ROUTINGKEY_PUT, content, correlationId);
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.CART_PUT+prod, RabbitConstants.CART_ROUTINGKEY_PUT+prod, content, correlationId);
|
||||
}
|
||||
public void putOrderCollect(String content) {
|
||||
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
|
||||
@@ -38,7 +40,7 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback {
|
||||
}
|
||||
public void printCoupons(String content){
|
||||
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.INTEGRAL_QUEUE_PUT, RabbitConstants.INTEGRAL_ROUTINGKEY_PUT, content, correlationId);
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.INTEGRAL_PUT, RabbitConstants.INTEGRAL_ROUTINGKEY_PUT, content, correlationId);
|
||||
}
|
||||
@Override
|
||||
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
|
||||
|
||||
Reference in New Issue
Block a user