37 lines
813 B
Java
37 lines
813 B
Java
package com.ifish7.mq.activemq;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.jms.Destination;
|
|
import javax.jms.JMSException;
|
|
import javax.jms.TextMessage;
|
|
|
|
import org.springframework.jms.core.JmsTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
public class ConsumerService {
|
|
|
|
@Resource(name="jmsTemplate")
|
|
private JmsTemplate jmsTemplate;
|
|
|
|
/**
|
|
* 接收消息
|
|
* @param destination
|
|
* @return
|
|
*/
|
|
public TextMessage receive(Destination destination) {
|
|
TextMessage tm=(TextMessage)jmsTemplate.receive(destination);
|
|
List list = new ArrayList<>();
|
|
try {
|
|
System.out.println("从队列--"+destination.toString()+"--接收到消息---"+tm.getText());
|
|
} catch (JMSException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return tm;
|
|
}
|
|
}
|