2 Replies Latest reply on Apr 28, 2009 3:42 AM by armsargis_sargis

    AMQ BlobMessage is not deleted when actual messages is deleted/rollbacked

    armsargis_sargis

      Hi, I have following test code:

       

      session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

      BlobTransferPolicy transferPolicy = new BlobTransferPolicy();

      transferPolicy.setUploadUrl("http://localhost:8161/fileserver/repo/");

      ...................

      producer = session.createProducer(queue);

      producer.send(createLargeMessage());

       

      and here is createLargeMessage method:

       

      private Message createLargeMessage() throws JMSException, FileNotFoundException {

         InputStream in = new FileInputStream("/srv/torrents/TEST.DAT");

         BlobMessage message = session.createBlobMessage(in);

          return message;

      }

       

      Code works fine and file uploaded into fileserver/repo/ dir, after from AMQ webconsole admin page:http://localhost:8161/admin I delete this message but actual uploaded file was remained in fileserver/repo dir.

       

      Another issue, I changed following lines in my code:

       

      session = (ActiveMQSession) connection.createSession(true, Session.AUTO_ACKNOWLEDGE);

      .....................

      producer = session.createProducer(queue);

      producer.send(createLargeMessage());

      session.rollback();

       

      and again the same uploaded file remains in fileserver/repo dir.

       

      I think may be adding additional method to:

       

      public interface BlobUploadStrategy {

       

          URL uploadFile(ActiveMQBlobMessage message, File file) throws JMSException, IOException;

       

          URL uploadStream(ActiveMQBlobMessage message, InputStream in) throws JMSException, IOException;

      }

       

      will help to solve this problem like:

       

          void deleteUploaded(String upResId) throws JMSException, IOException;

       

      and corresponding Strategy can override it and AMQ will call it internally. Of course if I understand correctly AMQ working logic :-).

       

      Thanks in advance.

        • 1. Re: AMQ BlobMessage is not deleted when actual messages is deleted/rollbacked
          gseben

          Hi there,

           

          If I understand correctly what's going on, you would like to have the file removed from the fileserver when you remove the message from the queue where it resides.

           

          I don't think that ActiveMQ will do that automatically for you. Removing the message from the queue or undoing the transaction will not erase the file that was uploaded. To delete the file you can use the DefaultBlobUploadStrategy or create your own BlobUploadStrategy.

           

          As an example you can check out the DefaultBlobUploadStrategyTest junit test that comes with the source code for ActiveMQ.

           

          Thanks,

          -Gio

          • 2. Re: AMQ BlobMessage is not deleted when actual messages is deleted/rollbacked
            armsargis_sargis

            Hi thanks for response, I know about DefaultBlobUploadStrategy and viewed Test class as you suggested. but as I understand:

             

            public void deleteFile(ActiveMQBlobMessage message) throws IOException, JMSException {

             

            }

             

            is not part of interface:

             

            public interface BlobUploadStrategy {

             

                URL uploadFile(ActiveMQBlobMessage message, File file) throws JMSException, IOException;

             

                URL uploadStream(ActiveMQBlobMessage message, InputStream in) throws JMSException, IOException;

            }

             

            and in test you calling delete explicitly like:

             

            DefaultBlobUploadStrategy strategy = new DefaultBlobUploadStrategy(policy);

            strategy.uploadFile(msg, file);

            .....

            strategy.deleteFile(msg);

             

            I think its nice to have something like  template pattern, and I will override for instance uploadFile() and deleteFile(), if there is Exception FUSE automatically will call deleteFile().

             

            But thanks again for response in fact it can be done by application developers also