49 import org.apache.qpid.amqp_1_0.jms.impl.*;
54 public static void main(String []args)
throws Exception {
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");
65 String DATA =
"abcdefghijklmnopqrstuvwxyz";
67 for(
int i=0; i < size; i ++) {
68 body += DATA.charAt(i%DATA.length());
71 ConnectionFactoryImpl factory =
new ConnectionFactoryImpl(host, port, user, password);
72 Destination dest = null;
73 if( destination.startsWith(
"topic://") ) {
74 dest =
new TopicImpl(destination);
76 dest =
new QueueImpl(destination);
79 Connection connection = factory.createConnection(user, password);
81 Session session = connection.createSession(
false, Session.AUTO_ACKNOWLEDGE);
82 MessageProducer producer = session.createProducer(dest);
83 producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
85 for(
int i=1; i <= messages; i ++) {
86 TextMessage msg = session.createTextMessage(
"#:"+i);
87 msg.setIntProperty(
"id", i);
89 if( (i % 1000) == 0) {
90 System.out.println(String.format(
"Sent %d messages", i));
94 producer.send(session.createTextMessage(
"SHUTDOWN"));
100 private static String env(String key, String defaultValue) {
101 String rc = System.getenv(key);
107 private static String arg(String []args,
int index, String defaultValue) {
108 if( index < args.length )