49 import org.apache.qpid.amqp_1_0.jms.impl.*;
54 public static void main(String []args)
throws JMSException {
56 String user = env(
"ACTIVEMQ_USER",
"admin");
57 String password = env(
"ACTIVEMQ_PASSWORD",
"password");
58 String host = env(
"ACTIVEMQ_HOST",
"localhost");
59 int port = Integer.parseInt(env(
"ACTIVEMQ_PORT",
"5672"));
60 String destination = arg(args, 0,
"queue://kingcobraq");
62 ConnectionFactoryImpl factory =
new ConnectionFactoryImpl(host, port, user, password);
63 Destination dest = null;
64 if( destination.startsWith(
"topic://") ) {
65 dest =
new TopicImpl(destination);
67 dest =
new QueueImpl(destination);
70 Connection connection = factory.createConnection(user, password);
72 Session session = connection.createSession(
false, Session.AUTO_ACKNOWLEDGE);
73 MessageConsumer consumer = session.createConsumer(dest);
74 long start = System.currentTimeMillis();
76 System.out.println(
"Waiting for messages...");
78 Message msg = consumer.receive();
79 if( msg instanceof TextMessage ) {
80 String body = ((TextMessage) msg).getText();
81 if(
"SHUTDOWN".equals(body)) {
82 long diff = System.currentTimeMillis() - start;
83 System.out.println(String.format(
"Received %d in %.2f seconds", count, (1.0*diff/1000.0)));
88 if( count != msg.getIntProperty(
"id") ) {
89 System.out.println(
"mismatch: "+count+
"!="+msg.getIntProperty(
"id"));
91 }
catch (NumberFormatException ignore) {
94 start = System.currentTimeMillis();
95 }
else if( count % 1000 == 0 ) {
96 System.out.println(String.format(
"Received %d messages.", count));
102 System.out.println(
"Unexpected message type: "+msg.getClass());
107 private static String env(String key, String defaultValue) {
108 String rc = System.getenv(key);
114 private static String arg(String []args,
int index, String defaultValue) {
115 if( index < args.length )