1 24 package perfs; 25 26 import javax.jms.*; 27 import javax.naming.*; 28 29 31 public class PerfsPublisher 32 { 33 static Context ictx = null; 34 35 public static void main(String [] args) throws Exception 36 { 37 ictx = new InitialContext(); 38 Topic queue = (Topic) ictx.lookup("topic"); 39 ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf"); 40 ictx.close(); 41 42 Connection cnx = cf.createConnection(); 43 Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE); 44 MessageProducer producer = sess.createProducer(queue); 45 46 BytesMessage msg = sess.createBytesMessage(); 47 byte[] content = new byte[1024]; 48 for (int i = 0; i< 1024; i++) 49 content[i] = (byte) (i & 0xFF); msg.writeBytes(content); 51 52 int counter = 0; 53 while (true) { 54 counter++; 55 msg.setLongProperty("time", System.currentTimeMillis()); 56 producer.send(msg); 57 msg.clearProperties(); 58 59 if (counter == 50) { 60 counter = 0; 61 } 63 } 64 } 65 } 66 | Popular Tags |