1 22 package org.jboss.ejb3.test.enventry; 23 24 import javax.annotation.PostConstruct; 25 import javax.annotation.Resource; 26 import javax.ejb.ActivationConfigProperty ; 27 import javax.ejb.MessageDriven ; 28 import javax.jms.Connection ; 29 import javax.jms.ConnectionFactory ; 30 import javax.jms.Destination ; 31 import javax.jms.Destination ; 32 import javax.jms.JMSException ; 33 import javax.jms.MapMessage ; 34 import javax.jms.Message ; 35 import javax.jms.MessageListener ; 36 import javax.jms.MessageProducer ; 37 import javax.jms.Session ; 38 import javax.naming.InitialContext ; 39 import javax.naming.NamingException ; 40 41 import org.jboss.logging.Logger; 42 43 47 @MessageDriven (name="TestEnvEntryMD", 48 activationConfig = { 49 @ActivationConfigProperty ( 50 propertyName = "destinationType", 51 propertyValue = "javax.jms.Queue"), 52 @ActivationConfigProperty ( 53 propertyName = "destination", 54 propertyValue = "queue/testEnvEntry") }) 55 public class TestEnvEntryMDBean implements MessageListener 56 { 57 private static final Logger log = Logger.getLogger(TestEnvEntryMDBean.class); 58 59 @Resource(mappedName="java:/JmsXA") 60 private ConnectionFactory connectionFactory; 61 62 @Resource(name="maxExceptions") private int maxExceptions = 4; 63 64 @Resource private int numExceptions = 3; 65 66 private int minExceptions = 1; 67 68 public void onMessage(Message msg) { 69 try { 70 Destination destination = msg.getJMSReplyTo(); 71 Connection conn = connectionFactory.createConnection(); 72 try { 73 Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); 74 MessageProducer replyProducer = session.createProducer(destination); 75 MapMessage replyMsg = session.createMapMessage(); 76 replyMsg.setJMSCorrelationID(msg.getJMSMessageID()); 77 78 replyMsg.setInt("maxExceptions", maxExceptions); 79 replyMsg.setInt("numExceptions", numExceptions); 80 replyMsg.setInt("minExceptions", minExceptions); 81 82 87 replyProducer.send(replyMsg); 88 } 89 finally { 90 conn.close(); 91 } 92 } 93 catch(JMSException e) { 94 throw new RuntimeException (e); 95 } 96 } 97 } 98 | Popular Tags |