Class AmqpMessageBody


  • public final class AmqpMessageBody
    extends Object
    This class encapsulates the body of a message. The AmqpMessageBodyType map to an AMQP specification message body types. Current implementation support DATA AMQP data type.

    Client should test for AmqpMessageBodyType before calling corresponding get method. Get methods not corresponding to the type of the body throws exception.

    How to check for AmqpMessageBodyType

     Object amqpValue;
     AmqpMessageBodyType bodyType = amqpAnnotatedMessage.getBody().getBodyType();
    
     switch (bodyType) {
         case DATA:
             byte[] payload = amqpAnnotatedMessage.getBody().getFirstData();
             System.out.println(new String(payload));
             break;
         case SEQUENCE:
             List<Object> sequenceData = amqpAnnotatedMessage.getBody().getSequence();
             sequenceData.forEach(System.out::println);
             break;
         case VALUE:
             amqpValue = amqpAnnotatedMessage.getBody().getValue();
             System.out.println(amqpValue);
             break;
         default:
             throw new RuntimeException(String.format(Locale.US, "Body type [%s] is not valid.", bodyType));
     }
     
    See Also:
    AmqpMessageBodyType, Amqp primitive data type., Amqp message format.
    • Method Detail

      • getBodyType

        public AmqpMessageBodyType getBodyType()
        Gets the AmqpMessageBodyType of the message.

        How to check for AmqpMessageBodyType

         Object amqpValue;
         AmqpMessageBodyType bodyType = amqpAnnotatedMessage.getBody().getBodyType();
        
         switch (bodyType) {
             case DATA:
                 byte[] payload = amqpAnnotatedMessage.getBody().getFirstData();
                 System.out.println(new String(payload));
                 break;
             case SEQUENCE:
                 List<Object> sequenceData = amqpAnnotatedMessage.getBody().getSequence();
                 sequenceData.forEach(System.out::println);
                 break;
             case VALUE:
                 amqpValue = amqpAnnotatedMessage.getBody().getValue();
                 System.out.println(amqpValue);
                 break;
             default:
                 throw new RuntimeException(String.format(Locale.US, "Body type [%s] is not valid.", bodyType));
         }
         
        Returns:
        AmqpBodyType type of the message.
      • getData

        public IterableStream<byte[]> getData()
        Gets an IterableStream of byte array containing only first byte array set on this AmqpMessageBody. This library only support one byte array at present, so the returned list will have only one element.

        Client should test for AmqpMessageBodyType before calling corresponding get method. Get methods not corresponding to the type of the body throws exception.

        How to check for AmqpMessageBodyType

         Object amqpValue;
         AmqpMessageBodyType bodyType = amqpAnnotatedMessage.getBody().getBodyType();
        
         switch (bodyType) {
             case DATA:
                 byte[] payload = amqpAnnotatedMessage.getBody().getFirstData();
                 System.out.println(new String(payload));
                 break;
             case SEQUENCE:
                 List<Object> sequenceData = amqpAnnotatedMessage.getBody().getSequence();
                 sequenceData.forEach(System.out::println);
                 break;
             case VALUE:
                 amqpValue = amqpAnnotatedMessage.getBody().getValue();
                 System.out.println(amqpValue);
                 break;
             default:
                 throw new RuntimeException(String.format(Locale.US, "Body type [%s] is not valid.", bodyType));
         }
         
        Returns:
        data set on AmqpMessageBody.
        Throws:
        IllegalArgumentException - If AmqpMessageBodyType is not DATA.
      • getFirstData

        public byte[] getFirstData()
        Gets first byte array set on this AmqpMessageBody. This library only support one byte array on Amqp Message at present.

        Client should test for AmqpMessageBodyType before calling corresponding get method. Get methods not corresponding to the type of the body throws exception.

        How to check for AmqpMessageBodyType

         Object amqpValue;
         AmqpMessageBodyType bodyType = amqpAnnotatedMessage.getBody().getBodyType();
        
         switch (bodyType) {
             case DATA:
                 byte[] payload = amqpAnnotatedMessage.getBody().getFirstData();
                 System.out.println(new String(payload));
                 break;
             case SEQUENCE:
                 List<Object> sequenceData = amqpAnnotatedMessage.getBody().getSequence();
                 sequenceData.forEach(System.out::println);
                 break;
             case VALUE:
                 amqpValue = amqpAnnotatedMessage.getBody().getValue();
                 System.out.println(amqpValue);
                 break;
             default:
                 throw new RuntimeException(String.format(Locale.US, "Body type [%s] is not valid.", bodyType));
         }
         
        Returns:
        data set on AmqpMessageBody.
        Throws:
        IllegalArgumentException - If AmqpMessageBodyType is not DATA.
        See Also:
        Amqp Message Format.
      • getSequence

        public List<Object> getSequence()
        Gets the unmodifiable AMQP Sequence set on this AmqpMessageBody. It support only one sequence at present.

        Client should test for AmqpMessageBodyType before calling corresponding get method. Get methods not corresponding to the type of the body throws exception.

        How to check for AmqpMessageBodyType

         Object amqpValue;
         AmqpMessageBodyType bodyType = amqpAnnotatedMessage.getBody().getBodyType();
        
         switch (bodyType) {
             case DATA:
                 byte[] payload = amqpAnnotatedMessage.getBody().getFirstData();
                 System.out.println(new String(payload));
                 break;
             case SEQUENCE:
                 List<Object> sequenceData = amqpAnnotatedMessage.getBody().getSequence();
                 sequenceData.forEach(System.out::println);
                 break;
             case VALUE:
                 amqpValue = amqpAnnotatedMessage.getBody().getValue();
                 System.out.println(amqpValue);
                 break;
             default:
                 throw new RuntimeException(String.format(Locale.US, "Body type [%s] is not valid.", bodyType));
         }
         
        Returns:
        sequence of this AmqpMessageBody instance.
        Throws:
        IllegalArgumentException - If AmqpMessageBodyType is not SEQUENCE.
        See Also:
        Amqp primitive data type., Amqp message format.
      • getValue

        public Object getValue()
        Gets the AMQP value set on this AmqpMessageBody instance. It can be any of the primitive AMQP data type.

        Client should test for AmqpMessageBodyType before calling corresponding get method. The 'Get' methods not corresponding to the type of the body throws exception.

        How to check for AmqpMessageBodyType

         Object amqpValue;
         AmqpMessageBodyType bodyType = amqpAnnotatedMessage.getBody().getBodyType();
        
         switch (bodyType) {
             case DATA:
                 byte[] payload = amqpAnnotatedMessage.getBody().getFirstData();
                 System.out.println(new String(payload));
                 break;
             case SEQUENCE:
                 List<Object> sequenceData = amqpAnnotatedMessage.getBody().getSequence();
                 sequenceData.forEach(System.out::println);
                 break;
             case VALUE:
                 amqpValue = amqpAnnotatedMessage.getBody().getValue();
                 System.out.println(amqpValue);
                 break;
             default:
                 throw new RuntimeException(String.format(Locale.US, "Body type [%s] is not valid.", bodyType));
         }
         
        Returns:
        value of this AmqpMessageBody instance.
        Throws:
        IllegalArgumentException - If AmqpMessageBodyType is not VALUE.
        See Also:
        Amqp primitive data type., Amqp message format.