这两天看了下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 {