SpringBoot如何集成ActiveMQ(二)
1.配置activemq消息监听QueueListener
@Component
public class QueueListener {
@JmsListener(destination = "publish.queue", containerFactory = "jmsListenerContainerQueue")
@SendTo("out.queue")
public String receive(String text){
System.out.println("QueueListener: consumer-a 收到一条信息: " + text);
return "consumer-a received : " + text;
}
}
2.SendTo 会将此方法返回的数据, 写入到 queue
@Component
public class TopicListener {
@JmsListener(destination = "publish.topic", containerFactory = "jmsListenerContainerTopic")
public void receive(String text){
System.out.println("TopicListener: consumer-a 收到一条信息: " + text);
}
}