1 24 package classic; 25 26 import javax.jms.*; 27 import javax.naming.*; 28 29 32 public class Producer 33 { 34 static Context ictx = null; 35 36 public static void main(String [] args) throws Exception 37 { 38 System.out.println(); 39 System.out.println("Produces messages on the queue and on the topic..."); 40 41 ictx = new InitialContext(); 42 Queue queue = (Queue) ictx.lookup("queue"); 43 Topic topic = (Topic) ictx.lookup("topic"); 44 ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf"); 45 ictx.close(); 46 47 Connection cnx = cf.createConnection(); 48 Session sess = cnx.createSession(true, 0); 49 MessageProducer producer = sess.createProducer(null); 50 51 TextMessage msg = sess.createTextMessage(); 52 53 int i; 54 for (i = 0; i < 10; i++) { 55 msg.setText("Test number " + i); 56 producer.send(queue, msg); 57 producer.send(topic, msg); 58 } 59 60 sess.commit(); 61 62 System.out.println(i + " messages sent."); 63 64 cnx.close(); 65 } 66 } 67 | Popular Tags |