8 Replies Latest reply on Sep 22, 2011 12:29 PM by Clebert Suconic

    JBoss 7 deletes all jms messages on shutdown

    Andrés Pereiro Newbie

      I'm using JBoss 7.0.1 Final with the "standalone-preview" configuration. I've changed the settings so that messages are persistent (persistence-enabled = true) and checked that the messages are stored in file system. 

      When I send persistent messages to a queue I can see the messages in the queue using a QueueBrowser  When I shutdown the JBoss, all messages are deleted, I can confirm that because if I send large messages the files are created on the messaginglargemessages directory and deleted on shutdown

      Is there something I'm missing in the configuration? Any ideas? 

      Thanks in advance, Andres.

       

      My code:

       

      {code}

      package org.jboss.sample.webservices;

       

      import java.util.ArrayList;

      import java.util.List;

       

      import javax.ejb.Stateless;

      import javax.jms.Queue;

      import javax.jms.QueueBrowser;

      import javax.jms.QueueConnection;

      import javax.jms.QueueConnectionFactory;

      import javax.jms.QueueSender;

      import javax.jms.QueueSession;

      import javax.jms.TextMessage;

      import javax.jws.WebMethod;

      import javax.jws.WebService;

      import javax.naming.InitialContext;

       

      @WebService()

      @Stateless

      public class WSToJMSService {

         

          private static final String CONNECTION_FACTORY = "/JmsXA";

          private static final String QUEUE_NAME = "queue/test";

       

          @WebMethod()

          public void process(String message, String queueName) throws Exception {

              send(message, queueName == null ? QUEUE_NAME : queueName);

          }

         

          private void send(String message, String queueName) throws Exception {

              QueueConnection conn = null;

              try {

                  //--- Initializing connection to JMS queue...

                  InitialContext iniCtx = new InitialContext();

                  QueueConnectionFactory qcf = (QueueConnectionFactory) iniCtx.lookup(CONNECTION_FACTORY);

                  conn = qcf.createQueueConnection();

                  QueueSession session = conn.createQueueSession(true, QueueSession.AUTO_ACKNOWLEDGE);

         

                  Queue msgQueue = (Queue) iniCtx.lookup(queueName);

                  QueueSender msgSender = session.createSender(msgQueue);

                  iniCtx.close();

                 

                  javax.jms.Message msg = session.createTextMessage(message);

                  msg.setStringProperty("timestampID", String.valueOf(System.currentTimeMillis()));

                 

      //            conn.start();

                  msgSender.send(msg);

                 

      //            session.commit();

             

                  //--- Releasing connection to JMS queue...

                  msgSender.close();

                  session.close();

       

      //            conn.stop();

                  //--- END Releasing connection.

                  System.out.println("WSToJMSService - releaseJMS: JMS connections released");

              } finally {

                  try {

                      if (conn != null) {

                          conn.close();

                      }

                  } catch (Exception e) {

                  }

              }

             

          }

         

          @SuppressWarnings("rawtypes")

          @WebMethod()

          public List<String> getTextMessagesContent(String queueName) throws Exception {

              QueueConnection conn = null;

              try {

                  //--- Initializing connection to JMS queue...

                  InitialContext iniCtx = new InitialContext();

                  QueueConnectionFactory qcf = (QueueConnectionFactory) iniCtx.lookup(CONNECTION_FACTORY);

                  conn = qcf.createQueueConnection();

                  QueueSession session = conn.createQueueSession(true, QueueSession.AUTO_ACKNOWLEDGE);

                 

                  Queue msgQueue = (Queue) iniCtx.lookup(queueName == null ? QUEUE_NAME : queueName);

                  QueueBrowser browser = session.createBrowser(msgQueue);

                  iniCtx.close();

                 

      //            conn.start();

       

                  List<String> messages = new ArrayList<String>();

                  java.util.Enumeration enumeration = browser.getEnumeration();

                  while (enumeration.hasMoreElements()) {

                      Object obj = enumeration.nextElement();

                      if (obj instanceof TextMessage) {

                          TextMessage txtMsg = (TextMessage) obj;

                          String text = txtMsg.getText();

                          messages.add(text);

                      }

                  }

                  session.close();

      //            conn.stop();

                  System.out.println("WSToJMSService - getTextMessagesContent");

                  return messages;

              } finally {

                  try {

                      if (conn != null) {

                          conn.close();

                      }

                  } catch (Exception e) {

                  }

              }

          }

       

      }

      {code}