ifishMQ commit
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package com.ifish7.mq;
|
||||
|
||||
/**
|
||||
* @author: yan.y
|
||||
* @Description:
|
||||
* @Date: Created in 14:33 2018/11/18
|
||||
* @Modified by:
|
||||
*/
|
||||
public class Main {
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.ifish7.mq.activemq.listener;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageListener;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.apache.activemq.store.journal.JournalTransactionStore.Tx;
|
||||
|
||||
public class QueueMessageListener implements MessageListener{
|
||||
|
||||
@Override
|
||||
public void onMessage(Message message) {
|
||||
|
||||
TextMessage tm = (TextMessage) message;
|
||||
try {
|
||||
System.out.println("收到的消息-----"+tm.getText());
|
||||
} catch (JMSException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user