Class AmqpMessageBody
- java.lang.Object
-
- com.azure.core.amqp.models.AmqpMessageBody
-
public final class AmqpMessageBody extends Object
This class encapsulates the body of a message. TheAmqpMessageBodyTypemap to an AMQP specification message body types. Current implementation supportDATAAMQP data type.Client should test for
AmqpMessageBodyTypebefore calling corresponding get method. Get methods not corresponding to the type of the body throws exception.How to check for
AmqpMessageBodyTypeObject 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)); }
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AmqpMessageBodyfromData(byte[] data)Creates instance ofAmqpMessageBodywith given byte array.static AmqpMessageBodyfromSequence(List<Object> sequence)Creates an instance ofAmqpMessageBodywith the givensequence.static AmqpMessageBodyfromValue(Object value)Creates an instance ofAmqpMessageBodywith the givenvalue.AmqpMessageBodyTypegetBodyType()Gets theAmqpMessageBodyTypeof the message.IterableStream<byte[]>getData()Gets anIterableStreamof byte array containing only first byte array set on thisAmqpMessageBody.byte[]getFirstData()Gets first byte array set on thisAmqpMessageBody.List<Object>getSequence()Gets the unmodifiable AMQP Sequence set on thisAmqpMessageBody.ObjectgetValue()Gets the AMQP value set on thisAmqpMessageBodyinstance.
-
-
-
Method Detail
-
fromData
public static AmqpMessageBody fromData(byte[] data)
Creates instance ofAmqpMessageBodywith given byte array.- Parameters:
data- used to create another instance ofAmqpMessageBody.- Returns:
- AmqpMessageBody Newly created instance.
- Throws:
NullPointerException- ifdatais null.
-
fromSequence
public static AmqpMessageBody fromSequence(List<Object> sequence)
Creates an instance ofAmqpMessageBodywith the givensequence. It supports only onesequenceat present.- Parameters:
sequence- used to create an instance ofAmqpMessageBody. A sequence can beListofobjects. Theobjectcan be any of the AMQP supported primitive data type.- Returns:
- newly created instance of
AmqpMessageBody. - Throws:
NullPointerException- ifsequenceis null.- See Also:
- Amqp primitive data type.
-
fromValue
public static AmqpMessageBody fromValue(Object value)
Creates an instance ofAmqpMessageBodywith the givenvalue. A value can be any of the AMQP supported primitive data type.- Parameters:
value- used to create an instance ofAmqpMessageBody.- Returns:
- newly created instance of
AmqpMessageBody. - Throws:
NullPointerException- ifvalueis null.- See Also:
- Amqp primitive data type.
-
getBodyType
public AmqpMessageBodyType getBodyType()
Gets theAmqpMessageBodyTypeof the message.How to check for
AmqpMessageBodyTypeObject 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 anIterableStreamof byte array containing only first byte array set on thisAmqpMessageBody. This library only support one byte array at present, so the returned list will have only one element.Client should test for
AmqpMessageBodyTypebefore calling corresponding get method. Get methods not corresponding to the type of the body throws exception.How to check for
AmqpMessageBodyTypeObject 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- IfAmqpMessageBodyTypeis notDATA.
-
getFirstData
public byte[] getFirstData()
Gets first byte array set on thisAmqpMessageBody. This library only support one byte array on Amqp Message at present.Client should test for
AmqpMessageBodyTypebefore calling corresponding get method. Get methods not corresponding to the type of the body throws exception.How to check for
AmqpMessageBodyTypeObject 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- IfAmqpMessageBodyTypeis notDATA.- See Also:
- Amqp Message Format.
-
getSequence
public List<Object> getSequence()
Gets the unmodifiable AMQP Sequence set on thisAmqpMessageBody. It support only onesequenceat present.Client should test for
AmqpMessageBodyTypebefore calling corresponding get method. Get methods not corresponding to the type of the body throws exception.How to check for
AmqpMessageBodyTypeObject 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
AmqpMessageBodyinstance. - Throws:
IllegalArgumentException- IfAmqpMessageBodyTypeis notSEQUENCE.- See Also:
- Amqp primitive data type., Amqp message format.
-
getValue
public Object getValue()
Gets the AMQP value set on thisAmqpMessageBodyinstance. It can be any of the primitive AMQP data type.Client should test for
AmqpMessageBodyTypebefore calling corresponding get method. The 'Get' methods not corresponding to the type of the body throws exception.How to check for
AmqpMessageBodyTypeObject 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
AmqpMessageBodyinstance. - Throws:
IllegalArgumentException- IfAmqpMessageBodyTypeis notVALUE.- See Also:
- Amqp primitive data type., Amqp message format.
-
-