zoukankan      html  css  js  c++  java
  • 程序启动 rabbitMq创建交换机,队列绑定交换机,以及设置绑定规则

    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("绑定规则"); } }
  • 相关阅读:
    linux运维之分析系统负载及运行状况
    linux运维之分析日志相关命令(1)
    centos7修改网卡名称为eth0
    LANMP环境编译参数查看方法
    自动化部署之搭建yum仓
    浙大 PAT 乙级 1001-1075 目录索引
    更改docker服务网段分配地址
    MySQL主从复制(Replication for Backup)
    MySQL读写分离-简单思考
    NGINX负载均衡缓存配置
  • 原文地址:https://www.cnblogs.com/woshuaile/p/15020865.html
Copyright © 2011-2022 走看看