1 22 package org.jboss.ejb3.test.appclient; 23 24 import javax.annotation.Resource; 25 import javax.ejb.ActivationConfigProperty ; 26 import javax.ejb.EJBException ; 27 import javax.ejb.MessageDriven ; 28 import javax.jms.Connection ; 29 import javax.jms.ConnectionFactory ; 30 import javax.jms.Destination ; 31 import javax.jms.JMSException ; 32 import javax.jms.Message ; 33 import javax.jms.MessageListener ; 34 import javax.jms.MessageProducer ; 35 import javax.jms.Session ; 36 37 import org.jboss.logging.Logger; 38 39 45 @MessageDriven (activationConfig = { 46 @ActivationConfigProperty (propertyName="destinationType", propertyValue="javax.jms.Queue"), 47 @ActivationConfigProperty (propertyName="destination", propertyValue="queue/messageReplier") 48 }) 49 public class MessageReplierBean implements MessageListener 50 { 51 private static final Logger log = Logger.getLogger(MessageReplierBean.class); 52 53 @Resource(mappedName="java:ConnectionFactory") 54 private ConnectionFactory connectionFactory; 55 56 public void onMessage(Message message) 57 { 58 try 59 { 60 if(message.getJMSReplyTo() != null) 61 { 62 Destination destination = message.getJMSReplyTo(); 63 64 Connection conn = connectionFactory.createConnection(); 65 try 66 { 67 Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); 68 MessageProducer producer = session.createProducer(destination); 69 producer.send(destination, message); 70 producer.close(); 71 session.close(); 72 } 73 finally 74 { 75 conn.close(); 76 } 77 } 78 else 79 log.info("no reply to specified"); 80 } 81 catch(JMSException e) 82 { 83 throw new EJBException (e); 84 } 85 } 86 } 87 | Popular Tags |