Configure Sending Messages from within JEE components
32.2. Sending Messages from within JEE components The JCA adapter can also be used for sending messages. The Connection Factory to use is configured by default in the jms-ds.xml file and is mapped to java:/JmsXA. Using this from within a JEE component will mean that the sending of the message will be done as part of the JTA transaction being used by the component. This means that if the sending of the message fails the overall transaction would rollback and the message be re-sent. Heres an example of this from within an MDB: @MessageDriven(name = "MDBMessageSendTxExample", activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/testQueue") }) @TransactionManagement(value= TransactionManagementType.CONTAINER) @TransactionAttribute(value= TransactionAttributeType.REQUIRED) @ResourceAdapter("hornetq-ra.rar") public class MDBMessageSendTxExample implements MessageListener { @Resource(mappedName = "java:/JmsXA") ConnectionFactory connectionFactory; @Resource(mappedName = "queue/replyQueue") Queue replyQueue; public void onMessage(Message message) { Connection conn = null; try { //Step 9. We know the client is sending a text message so we cast TextMessage textMessage = (TextMessage)message; //Step 10. get the text from the message. String text = textMessage.getText(); System.out.println("message " + text); conn = connectionFactory.createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = sess.createProducer(replyQueue); producer.send(sess.createTextMessage("this is a reply")); } catch (Exception e) { e.printStackTrace(); } finally { if(conn != null) { try { conn.close(); } catch (JMSException e) { } } } } } In JBoss Application Server you can use the JMS JCA adapter for sending messages from EJBs (including Session, Entity and Message-Driven Beans), Servlets (including jsps) and custom MBeans.