Mq - JiyangM/spring GitHub Wiki

  1. spring-boot-starter-amqp

2.发送消息

@Autowired
private RabbitTemplate rabbitTemplate;

// 路由使用直连的方式
rabbitTemplate.convertAndSend(AmqpQueueConfig.DIRECT, "routingKey", message);

消息消费

@Configuration
public class RabbitConfig {

    @Bean
    public Queue helloQueue() {
        return new Queue("hello");
    }
}

@RabbitListener @RabbitHandler

@Component
@RabbitListener(queues = "hello")
public class Receiver {

    @RabbitHandler
    public void process(String hello) {
        System.out.println("Receiver : " + hello);
    }

}