1 18 19 28 package org.apache.activemq.simple; 29 30 import javax.jms.Connection ; 31 import javax.jms.ConnectionFactory ; 32 import javax.jms.Destination ; 33 import javax.jms.JMSException ; 34 import javax.jms.Message ; 35 import javax.jms.MessageConsumer ; 36 import javax.jms.Session ; 37 38 import org.apache.activemq.ActiveMQConnectionFactory; 39 import org.apache.activemq.command.ActiveMQQueue; 40 41 public class Consumer { 42 43 public static void main(String [] args) throws JMSException , InterruptedException { 44 45 String url = "tcp://localhost:61616"; 46 if( args.length>0 ) { 47 url = args[0]; 48 } 49 50 ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); 51 Destination destination = new ActiveMQQueue("TEST.QUEUE"); 52 53 Connection connection = connectionFactory.createConnection(); 54 connection.start(); 55 56 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 57 MessageConsumer consumer = session.createConsumer(destination); 58 59 for( ;; ) { 60 System.out.println("Waiting for message."); 61 Message message = consumer.receive(); 62 if( message == null ) { 63 break; 64 } 65 System.out.println("Got message: " + message); 66 } 67 68 connection.close(); 69 } 70 } 71 72 | Popular Tags |