spring boot整合activemq rabbitmq
阿新 • • 發佈:2018-12-16
1.下載並安裝activemq服務(windows),下載地址:http://download.csdn.net/download/loveuserzzz/9938202
2.建立springboot工程,並引入依賴
<dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-all</artifactId> <version>5.15.0</version> </dependency>
<3.編寫生產者程式碼實現dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-activemq</artifactId> </dependency>
4.編寫客戶端實現@Component public class Producer implements CommandLineRunner{ @Autowired private JmsMessagingTemplate jmsMessagingTemplate; @Autowired private Queue queue; @Override public void run(String... args) throws Exception { send("Sample message"); System.out.println("Message was sent to the Queue"); } public void send(String msg) { this.jmsMessagingTemplate.convertAndSend(this.queue, msg); } }
@Component
public class Consumer {
@JmsListener(destination = "sample.queue")
public void receiveQueue(String text) {
System.out.println(text);
}
}
5.編寫application.properties
spring.activemq.in-memory=true spring.activemq.pool.enabled=false6.啟動activemq服務
7.啟動main執行檢視結果
下載原始碼:https://github.com/yifanzzz/springboot-mq.git
示例中包含activemq和rabbitmq兩部分,可以加群一起討論QQ:324070788