gradle.xml配置
compile group: 'org.springframework.boot', name: 'spring-boot-starter-activemq', version: '1.4.0.RELEASE'
compile group: 'org.apache.activemq', name: 'activemq-pool', version: '5.13.4'
application.properties配置
spring.activemq.broker-url=tcp://192.168.3.88:61616
spring.activemq.user=admin
spring.activemq.password=admin
spring.activemq.pool.enabled=true
spring.activemq.pool.max-connections=50
spring.activemq.pool.expiry-timeout=10000
spring.activemq.pool.idle-timeout=30000
/**
* 定义消费者
* @Description
* @author Qz
* @date 2018年3月27日
*
*/
@Component
public class Consumer {
@JmsListener(destination = "myTestQue")
public void receiveQueue(String text) {
System.out.println("消费者:来源于生产者对列的消息:"+text);
}
@JmsListener(destination = "myTestTopics")
public void receiveSub1(String text) {
System.out.println("消费者:Consumer1="+text);
}
// @JmsListener(destination = "myTestTopics")
// public void receiveSub2(String text) {
// System.out.println("消费者:Consumer2="+text);
// }
}
/**
* 定义生产者
* @Description
* @author Qz
* @date 2018年3月27日
*
*/
@Service
public class Producer {
private static final Logger logger=LoggerFactory.getLogger(Producer.class);
@Autowired
private JmsMessagingTemplate jmsMessagingTemplate;
@Autowired
private Queue queue;
@Autowired
private Topic topic;
/**
* 每5S执行一次
*/
@Scheduled(fixedRate=5000,initialDelay=3000)
public void send() {
//发送队列消息
this.jmsMessagingTemplate.convertAndSend(this.queue, "发队列消息了");
//发送订阅消息
this.jmsMessagingTemplate.convertAndSend(this.topic, "发主题消息了");
}
}
以上是通过其他博客整合 自己用的