Uploaded image for project: 'ActiveMQ Classic'
  1. ActiveMQ Classic
  2. AMQ-4887

ActiveMQBytesMessage will lost content if message's property was set before copy

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.9.0
    • 5.9.1, 5.10.0
    • Broker
    • None

    Description

      ActiveMQBytesMessage will lost content if message's property was set before copy. Here is the test code:

      Producer:
      MessageProducer producer;
      //initialize Connection, Session, MessageProducer
      byte[] bs = "bytes message".getBytes();
      BytesMessage message = session.createBytesMessage();
      message.writeBytes(bs); //write bytes to message 1

      for(int i=0; i< 0; i++){
      // then set message's propery 2
      message.setLongProperty("sendTime", System.currentTimeMillis());
      try

      { producer.send(message); }

      catch()

      { e.printStackTrace(); }

      }

      Consumer:

      MessageConsumer consumer
      //initailize Connection, Session, MessageConsumer
      for(int i=0; i<10; i++){
      ActiveMQBytesMessage msg = (ActiveMQBytesMessage)consumer.receive(60*1000);
      long sendTime = message.getLongProperty("sendTime");
      System.out.println("sendtime:" + sendTime);
      ByteSequence bs = message.getMessage().getContent();
      System.out.println("bytes data:" + new String(bs.getData()));
      }

      Expected result:
      consumer gets bytes data in all received messages

      Actual result:
      only the fisrt message has bytes data, all other messages lost bytes data, while long property value is not lost;

      Analysization:
      message gets copied when send, it will call storeContent() before copy, DataOutputStream dataOut will be closed and the data in dataOut will be set to conent. This works correctly if there are no property was set.

      when setLongProperty was called, it will call setObjectProperty() then will call initializeWriting(), here DataOutputStream dataOut will be create AGAIN.

      So when message was copied in second time, DataOutputStream dataOut is NOT null, but EMPTY, it will clear the value in content.

      suggestion:
      restore the content data to DataOutputStream dataOut when nitializeWriting()

      my fix:
      ActiveMQBytesMessage :
      private void initializeWriting() throws JMSException {
      669 The original code
      ......
      701
      //fix code
      if(this.content !=null && this.content.length >0){
      try

      { this.dataOut.write(this.content.getData()); }

      catch(IOException ioe)

      { throw JMSExceptionSupport.create(ioe); }

      }
      702 }

      Attachments

        1. ActiveMQBytesMessage.java.patch
          0.7 kB
          caoyunfei
        2. ActiveMQBytesMessageTest.java
          0.4 kB
          caoyunfei
        3. AMQ-4887.patch
          10 kB
          Timothy A. Bish
        4. AMQ-4887.patch
          1 kB
          Kevin Anthony Earls
        5. Consumer.java
          2 kB
          caoyunfei
        6. Producer.java
          2 kB
          caoyunfei

        Issue Links

          Activity

            People

              tabish Timothy A. Bish
              caoyunfei caoyunfei
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 24h
                  24h
                  Remaining:
                  Remaining Estimate - 24h
                  24h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified