|  |  | 
 |  |  | package cc.mrbird.febs.common.configure; | 
 |  |  |  | 
 |  |  | import cc.mrbird.febs.rabbit.constants.ExchangeConstants; | 
 |  |  | import cc.mrbird.febs.rabbit.constants.QueueConstants; | 
 |  |  | import cc.mrbird.febs.rabbit.constants.RouteKeyConstants; | 
 |  |  | import cc.mrbird.febs.rabbit.enumerates.RabbitQueueEnum; | 
 |  |  | import org.springframework.amqp.core.*; | 
 |  |  | import org.springframework.amqp.rabbit.connection.ConnectionFactory; | 
 |  |  | 
 |  |  | import org.springframework.context.annotation.Bean; | 
 |  |  | import org.springframework.context.annotation.Configuration; | 
 |  |  | import org.springframework.context.annotation.Scope; | 
 |  |  | import org.springframework.stereotype.Component; | 
 |  |  |  | 
 |  |  | import javax.annotation.Resource; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * @author wzy | 
 |  |  |  * @date 2021-09-25 | 
 |  |  |  **/ | 
 |  |  | @Configuration | 
 |  |  | public class RabbitConfigure { | 
 |  |  |  | 
 |  |  | 
 |  |  |         return new RabbitTemplate(connectionFactory); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public DirectExchange defaultExchange() { | 
 |  |  |         return new DirectExchange(ExchangeConstants.EXCHANGE_DEFAULT); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public Queue defaultQueue() { | 
 |  |  |         return new Queue(QueueConstants.QUEUE_DEFAULT); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public Binding defaultBind() { | 
 |  |  |         return BindingBuilder.bind(defaultQueue()).to(defaultExchange()).with(RouteKeyConstants.ROUTE_KEY_DEFAULT); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     // === 充值自动过期 延时  start === | 
 |  |  |     @Bean | 
 |  |  |     public DirectExchange delayTtlExchange() { | 
 |  |  |         return new DirectExchange(RabbitQueueEnum.ORDER_CANCEL_DELAY_TTL.getExchange()); | 
 |  |  |     public DirectExchange chargeDelayTtlExchange() { | 
 |  |  |         return new DirectExchange(RabbitQueueEnum.RUN_VIP_OPERATION_CHARGE_FAIL_TTL.getExchange()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public DirectExchange orderDelayExchange() { | 
 |  |  |         return new DirectExchange(RabbitQueueEnum.ORDER_CANCEL_DELAY.getExchange()); | 
 |  |  |     public Binding chargeDelayTtlBind() { | 
 |  |  |         return BindingBuilder.bind(chargeDelayTtlQueue()).to(chargeDelayTtlExchange()).with(RabbitQueueEnum.RUN_VIP_OPERATION_CHARGE_FAIL_TTL.getRoute()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public Queue orderDelayQueue() { | 
 |  |  |         return new Queue(RabbitQueueEnum.ORDER_CANCEL_DELAY.getQueue()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public Queue orderDelayQueueTtl() { | 
 |  |  |         return QueueBuilder.durable(RabbitQueueEnum.ORDER_CANCEL_DELAY_TTL.getQueue()) | 
 |  |  |     public Queue chargeDelayTtlQueue() { | 
 |  |  |         return QueueBuilder.durable(RabbitQueueEnum.RUN_VIP_OPERATION_CHARGE_FAIL_TTL.getQueue()) | 
 |  |  |                 //到期后转发的交换机 | 
 |  |  |                 .withArgument("x-dead-letter-exchange", RabbitQueueEnum.ORDER_CANCEL_DELAY.getExchange()) | 
 |  |  |                 .withArgument("x-dead-letter-exchange", RabbitQueueEnum.RUN_VIP_OPERATION_CHARGE_FAIL.getExchange()) | 
 |  |  |                 //到期后转发的路由键 | 
 |  |  |                 .withArgument("x-dead-letter-routing-key", RabbitQueueEnum.ORDER_CANCEL_DELAY.getRoute()) | 
 |  |  |                 .withArgument("x-dead-letter-routing-key", RabbitQueueEnum.RUN_VIP_OPERATION_CHARGE_FAIL.getRoute()) | 
 |  |  |                 .build(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public Binding orderDelayBind() { | 
 |  |  |         return BindingBuilder.bind(orderDelayQueue()).to(orderDelayExchange()).with(RabbitQueueEnum.ORDER_CANCEL_DELAY.getRoute()); | 
 |  |  |     public DirectExchange chargeDelayExchange() { | 
 |  |  |         return new DirectExchange(RabbitQueueEnum.RUN_VIP_OPERATION_CHARGE_FAIL.getExchange()); | 
 |  |  |     } | 
 |  |  |     @Bean | 
 |  |  |     public Queue chargeDelayQueue() { | 
 |  |  |         return new Queue(RabbitQueueEnum.RUN_VIP_OPERATION_CHARGE_FAIL.getQueue()); | 
 |  |  |     } | 
 |  |  |     @Bean | 
 |  |  |     public Binding chargeDelayBind() { | 
 |  |  |         return BindingBuilder.bind(chargeDelayQueue()).to(chargeDelayExchange()).with(RabbitQueueEnum.RUN_VIP_OPERATION_CHARGE_FAIL.getRoute()); | 
 |  |  |     } | 
 |  |  |     // === 充值自动过期 延时  end === | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     // start | 
 |  |  |     @Bean | 
 |  |  |     public DirectExchange agentReturnExchange() { | 
 |  |  |         return new DirectExchange(RabbitQueueEnum.RUN_VIP_OPERATION_CHARGE.getExchange()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public Binding orderDelayBindTtl() { | 
 |  |  |         return BindingBuilder.bind(orderDelayQueueTtl()).to(delayTtlExchange()).with(RabbitQueueEnum.ORDER_CANCEL_DELAY_TTL.getRoute()); | 
 |  |  |     public Queue agentReturnQueue() { | 
 |  |  |         return new Queue(RabbitQueueEnum.RUN_VIP_OPERATION_CHARGE.getQueue()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public Queue autoLevelUpAgentQueue() { | 
 |  |  |         return new Queue(QueueConstants.AGENT_AUTO_LEVEL_UP); | 
 |  |  |     public Binding agentReturnBind() { | 
 |  |  |         return BindingBuilder.bind(agentReturnQueue()).to(agentReturnExchange()).with(RabbitQueueEnum.RUN_VIP_OPERATION_CHARGE.getRoute()); | 
 |  |  |     } | 
 |  |  |     // end | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     // start | 
 |  |  |     @Bean | 
 |  |  |     public DirectExchange nodeUpExchange() { | 
 |  |  |         return new DirectExchange(RabbitQueueEnum.RUN_VIP_NODE_UP.getExchange()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public Binding autoLevelUpBind() { | 
 |  |  |         return BindingBuilder.bind(autoLevelUpAgentQueue()).to(defaultExchange()).with(RouteKeyConstants.ROUTE_KEY_DEFAULT); | 
 |  |  |     public Queue nodeUpQueue() { | 
 |  |  |         return new Queue(RabbitQueueEnum.RUN_VIP_NODE_UP.getQueue()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public DirectExchange agentReturnMoneyExchange() { | 
 |  |  |         return new DirectExchange(RabbitQueueEnum.AGENT_REUTRN_MONEY.getExchange()); | 
 |  |  |     public Binding nodeUpBind() { | 
 |  |  |         return BindingBuilder.bind(nodeUpQueue()).to(nodeUpExchange()).with(RabbitQueueEnum.RUN_VIP_NODE_UP.getRoute()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public Queue agentReturnMoneyQueue() { | 
 |  |  |         return new Queue(QueueConstants.AGENT_RETURN_MONEY); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public Binding agentReturnMoneyBind() { | 
 |  |  |         return BindingBuilder.bind(agentReturnMoneyQueue()).to(agentReturnMoneyExchange()).with(RabbitQueueEnum.AGENT_REUTRN_MONEY.getRoute()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public DirectExchange orderReturnMoneyExchange() { | 
 |  |  |         return new DirectExchange(RabbitQueueEnum.ORDER_RETURN_MONEY.getExchange()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public Queue orderReturnMoneyQueue() { | 
 |  |  |         return new Queue(QueueConstants.ORDER_RETURN_MONEY); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Bean | 
 |  |  |     public Binding orderReturnMoneyBind() { | 
 |  |  |         return BindingBuilder.bind(orderReturnMoneyQueue()).to(orderReturnMoneyExchange()).with(RabbitQueueEnum.ORDER_RETURN_MONEY.getRoute()); | 
 |  |  |     } | 
 |  |  |     // end | 
 |  |  |  | 
 |  |  | } |