1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.advisory.AdvisorySupport;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.command.ProducerInfo;
public class ConsumerTool implements MessageListener, ExceptionListener
{
private Destination destination;
private Session session;
public static void main(String[] args)
{
ConsumerTool consumer = new ConsumerTool();
consumer.run();
}
public void run()
{
try
{
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("null", "null", "failover://tcp://10.193.132.82:61616");
Connection connection = connectionFactory.createConnection();
connection.setExceptionListener(this);
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = session.createTopic("LOC.Test");
Destination advisoryDestination = AdvisorySupport.getProducerAdvisoryTopic(destination);
MessageConsumer consumer = session.createConsumer(advisoryDestination);
consumer.setMessageListener(this);
}
catch (JMSException ex)
{
Logger.getLogger(ConsumerTool.class.getName()).log(Level.SEVERE, null, ex);
}
finally
{
try
{
Thread.sleep(100000);
} catch (InterruptedException e)
{
}
}
}
public void onMessage(Message msg)
{
if (msg instanceof ActiveMQMessage)
{
ActiveMQMessage aMsg = (ActiveMQMessage)msg;
ProducerInfo prod = (ProducerInfo) aMsg.getDataStructure();
}
}
public void onException(JMSException jmse)
{
throw new UnsupportedOperationException("Not supported yet.");
}
} |
Partager