建立ActiveMq.java
@Slf4j
@Component
public class ActiveMq {
public static final String QUO_QUEUE = "12.**";
//@Autowired
//private Queue queue;
@JmsListener(destination = ActiveMqConfig.ACTIVE_QUEUE)
@SendTo(QUO_QUEUE)
public void receive(String msg){
log.info("接收数据:{}",msg);
}
}
建立ActiveMqConfig .java
@Configuration
public class ActiveMqConfig {
public static final String ACTIVE_QUEUE = "12.**";
@Bean
public Queue queue(){
try {
return new ActiveMQQueue(ACTIVE_QUEUE);
}catch (Exception e) {
return new ActiveMQQueue();
}
}
}
在对应的XML增加
<!-- 整合消息队列ActiveMQ -->
<!--ActiveMq-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
<version>1.5.0.RELEASE</version>
</dependency>
<!--消息队列连接池-->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>5.15.0</version>
</dependency>
<dependency>
<groupId>org.messaginghub</groupId>
<artifactId>pooled-jms</artifactId>
</dependency>
在YML里面增加activemq放在和spring的下一级
spring:
activemq:
broker-url: tcp://120.1.1.1:12345
user: active
password: 123456
close-timeout: 15s # 在考虑结束之前等待的时间
in-memory: true # 默认代理URL是否应该在内存中。如果指定了显式代理,则忽略此值。
non-blocking-redelivery: false # 是否在回滚回滚消息之前停止消息传递。这意味着当启用此命令时,消息顺序不会被保留。
send-timeout: 0 # 等待消息发送响应的时间。设置为0等待永远。
queue-name: 12.**
#topic-name: 12.**
# packages:
# trust-all: true #不配置此项,会报错
pool:
enabled: true
max-connections: 10 #连接池最大连接数
idle-timeout: 30000 #空闲的连接过期时间,默认为30秒