1 22 package org.jboss.test.jmsra.bean; 23 24 import javax.ejb.*; 25 import javax.jms.*; 26 import javax.naming.*; 27 28 import org.jboss.test.util.ejb.SessionSupport; 29 30 public class JMSSessionBean extends SessionSupport 31 { 32 public void sendToQueueAndTopic() 33 { 34 try 35 { 36 InitialContext ctx = new InitialContext(); 37 38 QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("java:/JmsXA"); 39 Queue q = (Queue) ctx.lookup("queue/testQueue"); 40 QueueConnection qc = qcf.createQueueConnection(); 41 QueueSession qs = null; 42 try 43 { 44 qs = qc.createQueueSession(true, Session.AUTO_ACKNOWLEDGE); 45 QueueSender sender = qs.createSender(q); 46 sender.send(qs.createMessage()); 47 } 48 finally 49 { 50 if (qs != null) 51 qs.close(); 52 if (qc != null) 53 qc.close(); 54 } 55 56 TopicConnectionFactory tcf = (TopicConnectionFactory) ctx.lookup("java:/JmsXA"); 57 Topic t = (Topic) ctx.lookup("topic/testTopic"); 58 TopicConnection tc = tcf.createTopicConnection(); 59 TopicSession ts = null; 60 try 61 { 62 ts = tc.createTopicSession(true, Session.AUTO_ACKNOWLEDGE); 63 TopicPublisher publisher = ts.createPublisher(t); 64 publisher.publish(ts.createMessage()); 65 } 66 finally 67 { 68 if (ts != null) 69 ts.close(); 70 if (tc != null) 71 tc.close(); 72 } 73 } 74 catch (Exception e) 75 { 76 throw new EJBException(e); 77 } 78 } 79 } | Popular Tags |