1 23 package bridge; 24 25 import javax.jms.Connection ; 26 import javax.jms.ConnectionFactory ; 27 import javax.jms.Destination ; 28 import javax.jms.MessageProducer ; 29 import javax.jms.Session ; 30 import javax.jms.TextMessage ; 31 32 35 public class BridgeProducer { 36 public static void main(String [] args) throws Exception { 37 javax.naming.Context jndiCtx = new javax.naming.InitialContext (); 38 Destination joramDest = (Destination ) jndiCtx.lookup("joramTopic"); 39 ConnectionFactory joramCF = (ConnectionFactory ) jndiCtx.lookup("joramCF"); 40 jndiCtx.close(); 41 42 Connection joramCnx = joramCF.createConnection(); 43 Session joramSess = joramCnx.createSession(true, 0); 44 MessageProducer joramSender = joramSess.createProducer(joramDest); 45 46 TextMessage msg = joramSess.createTextMessage(); 47 48 for (int i = 1; i < 11; i++) { 49 msg.setText("Joram message number " + i); 50 System.out.println("send msg = " + msg.getText()); 51 joramSender.send(msg); 52 } 53 54 joramSess.commit(); 55 56 joramCnx.close(); 57 } 58 } 59 | Popular Tags |