• 程序启动 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("绑定规则"); } }
  • 相关阅读:
    Nginx源码编译安装与负载均衡配置实践
    jquery_file_upload in Rails(ajax实现多张图片上传)
    Nokogiri相关网站
    rails中 url和path的区别
    Unique Paths
    Kinect for windows的脸部识别
    .Net给图片添加水印效果
    大型高性能ASP.NET系统架构设计
    如何来提高网站的访问速度,其中包括服务器的配置建议,asp.NET代码的编写及前端页面的优化等等
    URL中#号(井号)的作用
  • 原文地址:https://www.cnblogs.com/woshuaile/p/15020865.html
Copyright © 2020-2023  润新知