1 24 package archi; 25 26 import javax.jms.*; 27 import javax.naming.*; 28 29 public class Publisher 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("Publishes messages..."); 37 38 ictx = new InitialContext(); 39 ConnectionFactory cnxF = (ConnectionFactory) ictx.lookup("cf0"); 40 Topic dest = (Topic) ictx.lookup("topic"); 41 ictx.close(); 42 43 Connection cnx = cnxF.createConnection(); 44 Session session = cnx.createSession(true, 0); 45 46 MessageProducer pub = session.createProducer(dest); 47 48 TextMessage message = session.createTextMessage(); 49 50 int i; 51 for (i = 0; i < 10; i ++) { 52 message.setText("Message " + i); 53 pub.send(message); 54 } 55 session.commit(); 56 57 System.out.println(i + " messages published."); 58 59 cnx.close(); 60 } 61 } 62 | Popular Tags |