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