导航页:https://blog.csdn.net/baokx/article/details/100745165
新建工程,pom和配置等同于生产者
新建消费者:
package com.baokx.boot.activemq.consumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.TextMessage;
import java.util.UUID;
/**
* @author kexiang.bao
* @create 2019-09-18 20:21
*/
@Component
public class QueueConsumer {
@JmsListener(destination = "${my-destination}")
public void receive(TextMessage textMessage) throws JMSException {
System.out.println(textMessage.getText());
}
}
运行主启动程序,可接收到之前生产者发送的消息: