src/main/java/com/xcong/excoin/configurations/RabbitMqConfig.java
@@ -13,6 +13,8 @@ import org.springframework.context.annotation.Scope; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; /** * @author wzy @@ -122,6 +124,9 @@ public static final String QUEUE_MARKET_BUSSINESS = "QUEUE_MARKET_BUSSINESS"; public static final String ROUTING_KEY_DELAY = "route.delay"; public static final String QUEUE_DELAY = "queue.delay"; @Resource private ConnectionFactory connectionFactory; @@ -146,6 +151,21 @@ } @Bean public Queue delayQueue() { Map<String, Object> params = new HashMap<>(); // x-dead-letter-exchange 声明了队列里的死信转发到的DLX名称, params.put("x-dead-letter-exchange", EXCHANGE_ONE); // x-dead-letter-routing-key 声明了这些死信在转发时携带的 routing-key 名称。 params.put("x-dead-letter-routing-key", ROUTING_KEY_DELAY); return new Queue(QUEUE_DELAY, true, false, false, params); } @Bean public Binding delayBinding() { return BindingBuilder.bind(delayQueue()).to(defaultExchange()).with(ROUTING_KEY_DELAY); } @Bean public Queue marketBussinessQueue() { return new Queue(QUEUE_MARKET_BUSSINESS); } src/main/java/com/xcong/excoin/rabbit/consumer/OtcConsumer.java
@@ -6,14 +6,22 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; import java.util.Date; @Slf4j @Component @ConditionalOnProperty(prefix = "app", name = "otc-job", havingValue = "true") public class OtcConsumer { @RabbitListener(queues = RabbitMqConfig.QUEUE_MARKET_BUSSINESS) // @RabbitListener(queues = RabbitMqConfig.QUEUE_MARKET_BUSSINESS) public void marketBussiness(String content) { log.info("---->{}", content); } // @RabbitListener(queues = RabbitMqConfig.QUEUE_DELAY) public void delayOrder() { log.info("---->{}", new Date()); } } src/main/java/com/xcong/excoin/rabbit/producer/OtcProducter.java
@@ -9,6 +9,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Date; @Slf4j @Component public class OtcProducter implements RabbitTemplate.ConfirmCallback { @@ -28,6 +30,14 @@ rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_ONE, RabbitMqConfig.ROUTINGKEY_MARKET_BUSSINESS, content, correlationData); } public void sendDelayOrderMsg(String content) { log.info("-----{}", new Date()); rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_ONE, RabbitMqConfig.ROUTING_KEY_DELAY, message -> { message.getMessageProperties().setExpiration(60 + ""); return message; }); } @Override public void confirm(CorrelationData correlationData, boolean b, String s) { src/main/resources/mapper/otc/OtcOrderDao.xml
@@ -68,7 +68,7 @@ select count(1) from otc_order where entrust_member_id=#{entrustMemberId} and entrust_member_id!=member_id <if test="status != null"> and status #{status} and status = #{status} </if> </select>