You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
286 lines
8.0 KiB
286 lines
8.0 KiB
package com.example.demo.config;
|
|
|
|
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.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;
|
|
|
|
/**
|
|
* RabbitMQ配置类
|
|
* 配置消息队列、交换机以及它们之间的绑定关系
|
|
*/
|
|
@Configuration
|
|
public class RabbitMQConfig {
|
|
|
|
public static final String LOG_QUEUE = "operation_log_queue";
|
|
public static final String LOG_EXCHANGE = "operation_log_exchange";
|
|
|
|
// 收款流程相关队列和交换机常量定义
|
|
public static final String CASH_COLLECTION_EXCHANGE = "cash_collection_exchange";
|
|
public static final String COLLECTION_CREATED_QUEUE = "collection_created_queue";
|
|
public static final String COLLECTION_AUDITED_QUEUE = "collection_audited_queue";
|
|
public static final String COLLECTION_COMPLETED_QUEUE = "collection_completed_queue";
|
|
public static final String COLLECTION_CANCELLED_QUEUE = "collection_cancelled_queue";
|
|
public static final String COLLECTION_REJECTED_QUEUE = "collection_rejected_queue";
|
|
|
|
// 退款流程相关队列和交换机常量定义
|
|
public static final String CASH_REFUND_EXCHANGE = "cash_refund_exchange";
|
|
public static final String REFUND_CREATED_QUEUE = "refund_created_queue";
|
|
public static final String REFUND_REVIEWED_QUEUE = "refund_reviewed_queue";
|
|
public static final String REFUND_EXECUTED_QUEUE = "refund_executed_queue";
|
|
public static final String REFUND_COMPLETED_QUEUE = "refund_completed_queue";
|
|
public static final String REFUND_REJECTED_QUEUE = "refund_rejected_queue";
|
|
|
|
@Bean
|
|
public Queue logQueue() {
|
|
return new Queue(LOG_QUEUE, true);
|
|
}
|
|
|
|
@Bean
|
|
public TopicExchange logExchange() {
|
|
return new TopicExchange(LOG_EXCHANGE);
|
|
}
|
|
|
|
@Bean
|
|
public Binding binding() {
|
|
return BindingBuilder.bind(logQueue())
|
|
.to(logExchange())
|
|
.with("log.*");
|
|
}
|
|
|
|
/**
|
|
* 创建收款流程交换机
|
|
* @return TopicExchange对象
|
|
*/
|
|
@Bean
|
|
public TopicExchange cashCollectionExchange() {
|
|
return new TopicExchange(CASH_COLLECTION_EXCHANGE);
|
|
}
|
|
|
|
/**
|
|
* 创建收款创建队列
|
|
* @return Queue对象
|
|
*/
|
|
@Bean
|
|
public Queue collectionCreatedQueue() {
|
|
return new Queue(COLLECTION_CREATED_QUEUE, true);
|
|
}
|
|
|
|
/**
|
|
* 创建收款审核队列
|
|
* @return Queue对象
|
|
*/
|
|
@Bean
|
|
public Queue collectionAuditedQueue() {
|
|
return new Queue(COLLECTION_AUDITED_QUEUE, true);
|
|
}
|
|
|
|
/**
|
|
* 创建收款完成队列
|
|
* @return Queue对象
|
|
*/
|
|
@Bean
|
|
public Queue collectionCompletedQueue() {
|
|
return new Queue(COLLECTION_COMPLETED_QUEUE, true);
|
|
}
|
|
|
|
/**
|
|
* 创建收款取消队列
|
|
* @return Queue对象
|
|
*/
|
|
@Bean
|
|
public Queue collectionCancelledQueue() {
|
|
return new Queue(COLLECTION_CANCELLED_QUEUE, true);
|
|
}
|
|
|
|
/**
|
|
* 创建收款拒绝队列
|
|
* @return Queue对象
|
|
*/
|
|
@Bean
|
|
public Queue collectionRejectedQueue() {
|
|
return new Queue(COLLECTION_REJECTED_QUEUE, true);
|
|
}
|
|
|
|
/**
|
|
* 创建退款流程交换机
|
|
* @return TopicExchange对象
|
|
*/
|
|
@Bean
|
|
public TopicExchange cashRefundExchange() {
|
|
return new TopicExchange(CASH_REFUND_EXCHANGE);
|
|
}
|
|
|
|
/**
|
|
* 创建退款创建队列
|
|
* @return Queue对象
|
|
*/
|
|
@Bean
|
|
public Queue refundCreatedQueue() {
|
|
return new Queue(REFUND_CREATED_QUEUE, true);
|
|
}
|
|
|
|
/**
|
|
* 创建退款审核队列
|
|
* @return Queue对象
|
|
*/
|
|
@Bean
|
|
public Queue refundReviewedQueue() {
|
|
return new Queue(REFUND_REVIEWED_QUEUE, true);
|
|
}
|
|
|
|
/**
|
|
* 创建退款执行队列
|
|
* @return Queue对象
|
|
*/
|
|
@Bean
|
|
public Queue refundExecutedQueue() {
|
|
return new Queue(REFUND_EXECUTED_QUEUE, true);
|
|
}
|
|
|
|
/**
|
|
* 创建退款完成队列
|
|
* @return Queue对象
|
|
*/
|
|
@Bean
|
|
public Queue refundCompletedQueue() {
|
|
return new Queue(REFUND_COMPLETED_QUEUE, true);
|
|
}
|
|
|
|
/**
|
|
* 创建退款拒绝队列
|
|
* @return Queue对象
|
|
*/
|
|
@Bean
|
|
public Queue refundRejectedQueue() {
|
|
return new Queue(REFUND_REJECTED_QUEUE, true);
|
|
}
|
|
|
|
/**
|
|
* 绑定收款创建队列到收款交换机
|
|
* @return Binding对象
|
|
*/
|
|
@Bean
|
|
public Binding collectionCreatedBinding() {
|
|
return BindingBuilder.bind(collectionCreatedQueue())
|
|
.to(cashCollectionExchange())
|
|
.with("collection.created");
|
|
}
|
|
|
|
/**
|
|
* 绑定收款审核队列到收款交换机
|
|
* @return Binding对象
|
|
*/
|
|
@Bean
|
|
public Binding collectionAuditedBinding() {
|
|
return BindingBuilder.bind(collectionAuditedQueue())
|
|
.to(cashCollectionExchange())
|
|
.with("collection.audited");
|
|
}
|
|
|
|
/**
|
|
* 绑定收款完成队列到收款交换机
|
|
* @return Binding对象
|
|
*/
|
|
@Bean
|
|
public Binding collectionCompletedBinding() {
|
|
return BindingBuilder.bind(collectionCompletedQueue())
|
|
.to(cashCollectionExchange())
|
|
.with("collection.completed");
|
|
}
|
|
|
|
/**
|
|
* 绑定收款取消队列到收款交换机
|
|
* @return Binding对象
|
|
*/
|
|
@Bean
|
|
public Binding collectionCancelledBinding() {
|
|
return BindingBuilder.bind(collectionCancelledQueue())
|
|
.to(cashCollectionExchange())
|
|
.with("collection.cancelled");
|
|
}
|
|
|
|
/**
|
|
* 绑定收款拒绝队列到收款交换机
|
|
* @return Binding对象
|
|
*/
|
|
@Bean
|
|
public Binding collectionRejectedBinding() {
|
|
return BindingBuilder.bind(collectionRejectedQueue())
|
|
.to(cashCollectionExchange())
|
|
.with("collection.rejected");
|
|
}
|
|
|
|
/**
|
|
* 绑定退款创建队列到退款交换机
|
|
* @return Binding对象
|
|
*/
|
|
@Bean
|
|
public Binding refundCreatedBinding() {
|
|
return BindingBuilder.bind(refundCreatedQueue())
|
|
.to(cashRefundExchange())
|
|
.with("refund.created");
|
|
}
|
|
|
|
/**
|
|
* 绑定退款审核队列到退款交换机
|
|
* @return Binding对象
|
|
*/
|
|
@Bean
|
|
public Binding refundReviewedBinding() {
|
|
return BindingBuilder.bind(refundReviewedQueue())
|
|
.to(cashRefundExchange())
|
|
.with("refund.reviewed");
|
|
}
|
|
|
|
/**
|
|
* 绑定退款执行队列到退款交换机
|
|
* @return Binding对象
|
|
*/
|
|
@Bean
|
|
public Binding refundExecutedBinding() {
|
|
return BindingBuilder.bind(refundExecutedQueue())
|
|
.to(cashRefundExchange())
|
|
.with("refund.executed");
|
|
}
|
|
|
|
/**
|
|
* 绑定退款完成队列到退款交换机
|
|
* @return Binding对象
|
|
*/
|
|
@Bean
|
|
public Binding refundCompletedBinding() {
|
|
return BindingBuilder.bind(refundCompletedQueue())
|
|
.to(cashRefundExchange())
|
|
.with("refund.completed");
|
|
}
|
|
|
|
/**
|
|
* 绑定退款拒绝队列到退款交换机
|
|
* @return Binding对象
|
|
*/
|
|
@Bean
|
|
public Binding refundRejectedBinding() {
|
|
return BindingBuilder.bind(refundRejectedQueue())
|
|
.to(cashRefundExchange())
|
|
.with("refund.rejected");
|
|
}
|
|
|
|
@Bean
|
|
public MessageConverter messageConverter() {
|
|
return new Jackson2JsonMessageConverter();
|
|
}
|
|
|
|
@Bean
|
|
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
|
|
RabbitTemplate template = new RabbitTemplate(connectionFactory);
|
|
template.setMessageConverter(messageConverter());
|
|
return template;
|
|
}
|
|
}
|