1 24 package archi; 25 26 import javax.jms.*; 27 import javax.naming.*; 28 29 public class Sender 30 { 31 static Context ictx = null; 32 33 public static void main(String argv[]) throws Exception 34 { 35 System.out.println(); 36 System.out.println("Sends messages on the queue..."); 37 38 ictx = new InitialContext(); 39 ConnectionFactory cnxF = (ConnectionFactory) ictx.lookup("cf0"); 40 Queue dest = (Queue) ictx.lookup("queue"); 41 ictx.close(); 42 43 Connection cnx = cnxF.createConnection(); 44 Session session = cnx.createSession(true, 0); 45 MessageProducer sender = session.createProducer(dest); 46 47 TextMessage message = session.createTextMessage(); 48 49 int i; 50 for (i = 0; i < 10; i ++) { 51 message.setText("Message " + i); 52 sender.send(message); 53 } 54 55 session.commit(); 56 57 System.out.println(i + " messages sent."); 58 59 cnx.close(); 60 } 61 } 62 | Popular Tags |