springboot利用activemq监听接口
时间: 2023-10-09 09:07:07 浏览: 45
以下是Spring Boot和ActiveMQ集成的基本步骤:
1. 在pom.xml中添加以下依赖:
```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
```
2. 在application.yml中添加以下配置:
```
spring.activemq.broker-url=tcp://localhost:61616
```
3. 创建一个JMS消息监听器:
```
@Component
public class MyJmsListener {
@JmsListener(destination = "myQueue")
public void processMessage(String message) {
System.out.println("Received message: " + message);
}
}
```
4. 在启动类中添加@EnableJms注解:
```
@SpringBootApplication
@EnableJms
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
```
5. 现在,当消息被发送到“myQueue”队列时,MyJmsListener中的processMessage方法将被调用。
注意:要使用ActiveMQ,您必须先启动ActiveMQ服务器。