依赖
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-amqp</artifactId>
    <version>3.2.10</version>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
如何声明队列、如何创建消费者?

由配置类完成:

对于consumer,也可直接@component注入容器

consumer涉及注解:

@Configuration
@Profile({"tut2", "work-queues"})
public class Tut2Config {
    @Bean
    public Queue queue() {
        return new Queue("hello_a");
    }

    @Profile({"receiver"})
    private static class ReceiverConfig {
        @Bean
        public Tut2Receiver receiver1() {
            return new Tut2Receiver(1);
        }

        @Bean
        public Tut2Receiver receiver2() {
            return new Tut2Receiver(2);
        }
    }

    @Profile({"sender"})
    @Bean
    public Tut2Sender sender() {
        return new Tut2Sender();
    }
}
如何发送消息?
fanout使用示例
direct使用示例
topic使用示例
转载请注明出处