Bootstrap

springboot中rabbitmq集成——单项目

这两天看了下activemq和rabbitmq,现在跟大家分享下rabbitmq在springboot中的集成及使用。

依赖

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

具体代码:

@SpringBootApplication
public class RabbitmqApplication implements CommandLineRunner{
   

    @Autowired
    RabbitTemplate rabbitTemplate;//使用springboot配置好的队列RabbitTemplate

    public static void main(String[] args) {

        SpringApplication.run(RabbitmqApplication.class, args);
    }

    /**
     * 定义目的地队列,命名为my-rabbitmq
     * 这里实际上是要往rabbitmq里注册队列名称
     * */
    @Bean
    public Queue myQueue(){
        return new Queue("my-rabbitmq");
    }

    public void run(String... args) throws Exception {

        

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;