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 ForeignPublisher { 36 public static void main(String [] args) throws Exception { 37 javax.naming.Context jndiCtx = new javax.naming.InitialContext (); 38 Destination foreignDest = (Destination ) jndiCtx.lookup("foreignTopic"); 39 ConnectionFactory foreignCF = (ConnectionFactory ) jndiCtx.lookup("foreignCF"); 40 jndiCtx.close(); 41 42 Connection foreignCnx = foreignCF.createConnection(); 43 Session foreignSess = foreignCnx.createSession(true, 0); 44 MessageProducer foreignSender = foreignSess.createProducer(foreignDest); 45 46 TextMessage foreignMsg = foreignSess.createTextMessage(); 47 48 for (int i = 1; i < 11; i++) { 49 foreignMsg.setText("topic Foreign message number " + i); 50 System.out.println("send msg = " + foreignMsg.getText()); 51 foreignSender.send(foreignMsg); 52 } 53 54 foreignSess.commit(); 55 56 57 foreignCnx.close(); 58 } 59 } 60 | Popular Tags |