跟我学MQ系列之三rabbitMQ与springcloud集成应用

1,配置文件application.yml

spring:
  rabbitmq:
    username: guest
    password: guest
    host: ip
    port: 5672

2,pom.xml

  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
  </dependency>

 

3,RabbitConfig.java

public class RabbitMQConst {

    /**
     * email交换机
     */
    public static final String EMAIL_EXCHANGE = "email_exchange";

    /**
     * 邮件队列
     */
    public static final String EMAIL_QUEUE = "email_queue";

    /**
     * es队列
     */
    public final static String esQueue = "es_queue";

    /**
     * es交换机
     */
    public final static String esExchange = "es_exchange";


    public final static String esBingKey = "es_exchange";
}
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static pers.fjl.common.constant.RabbitMQConst.*;


@Configuration
public class RabbitConfig {

    @Bean
    public Queue exQueue(){
        return new Queue(esQueue,true);
    }

    @Bean
    DirectExchange exchange(){
        return new DirectExchange(esExchange,true,false);
    }

    @Bean
    Binding binding(Queue exQueue, DirectExchange exchange){
        return BindingBuilder.bind(exQueue).to(exchange).with(esBingKey);
    }

    @Bean
    public Queue emailQueue() {
        return new Queue(EMAIL_QUEUE, true);
    }

    @Bean
    public FanoutExchange emailExchange() {
        return new FanoutExchange(EMAIL_EXCHANGE, true, false);
    }

    @Bean
    public Binding bindingEmailDirect() {
        return BindingBuilder.bind(emailQueue()).to(emailExchange());
    }

}

 

posted on 2022-06-27 16:07  让代码飞  阅读(171)  评论(0)    收藏  举报

导航

一款免费在线思维导图工具推荐:https://www.processon.com/i/593e9a29e4b0898669edaf7f?full_name=python