package application.config.rabbit;
import application.config.CommonConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 交换机配置类
*
* @author
* @date 2021/1/18/0018 15:17
*/
@Configuration
@Slf4j
public class RabbitMqConfig {
@Bean
public RabbitListenerContainerFactory<?> rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setMessageConverter(new Jackson2JsonMessageConverter());
factory.setAcknowledgeMode(AcknowledgeMode.MANUAL);
return factory;
}
//*******************用户【刷脸】,企业相关交换机
//bean的名称自定义约束好即可,
// MqConfigConstants.EXCHANGE_ACCOUNT 常量的名字自定义也可
@Bean("accountExchange")
public TopicExchange accountExchange() {
return new TopicExchange(MqConfigConstants.EXCHANGE_ACCOUNT, true, false);
}
@Bean("companyExchange")
public TopicExchange companyExchange() {
return new TopicExchange(MqConfigConstants.EXCHANGE_COMPANY, true, false);
}
//*************************[刷脸]用户、企业队列
@Bean
public Queue faceQueue() {
//队列持久
return new Queue(MqConfigConstants.FACE_STATUS_CHANGE_KEY_PRE_PASS, true);
}
@Bean
public Queue accountQueue() {
return new Queue(MqConfigConstants.ACCOUNT_STATUS_CHANGE_KEY_PRE, true);
}
@Bean
public Queue companyQueue() {
return new Queue(MqConfigConstants.COMPANY_STATUS_CHANGE_KEY_PRE_PASS, true);
}
//****************************绑定
// 刷脸[绑定规则可以具体到某一个值 如 face.status.0这种绑定的为0的数据,如果想模糊绑定 face.status.* 或者face.status.# #匹配的是当前和子类]
// 用户 。企业
@Bean
public Binding bindingFacePass() {
return BindingBuilder.bind(faceQueue()).
to(accountExchange())
.with("绑定规则");
}
@Bean
public Binding bindingFaceFail() {
return BindingBuilder.bind(faceQueue()).
to(accountExchange())
.with("绑定规则" );
}
@Bean
public Binding bindingAccountPass() {
return BindingBuilder.bind(accountQueue()).
to(accountExchange())
.with("绑定规则");
}
@Bean
public Binding bindingAccountFail() {
return BindingBuilder.bind(accountQueue()).
to(accountExchange())
.with("绑定规则");
}
@Bean
public Binding bindingCompanyPass() {
return BindingBuilder.bind(companyQueue()).
to(companyExchange())
.with("绑定规则");
}
@Bean
public Binding bindingCompanyFail() {
return BindingBuilder.bind(companyQueue()).
to(companyExchange())
.with("绑定规则");
}
}