Class AmqpMessageBody
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)); }
-
Method Summary
Modifier and TypeMethodDescriptionstatic AmqpMessageBody
fromData
(byte[] data) Creates instance ofAmqpMessageBody
with given byte array.static AmqpMessageBody
fromSequence
(List<Object> sequence) Creates an instance ofAmqpMessageBody
with the givensequence
.static AmqpMessageBody
Creates an instance ofAmqpMessageBody
with the givenvalue
.Gets theAmqpMessageBodyType
of the message.IterableStream<byte[]>
getData()
Gets anIterableStream
of byte array containing only first byte array set on thisAmqpMessageBody
.byte[]
Gets first byte array set on thisAmqpMessageBody
.Gets the unmodifiable AMQP Sequence set on thisAmqpMessageBody
.getValue()
Gets the AMQP value set on thisAmqpMessageBody
instance.
-
Method Details
-
fromData
Creates instance ofAmqpMessageBody
with given byte array.- Parameters:
data
- used to create another instance ofAmqpMessageBody
.- Returns:
- AmqpMessageBody Newly created instance.
- Throws:
NullPointerException
- ifdata
is null.
-
fromSequence
Creates an instance ofAmqpMessageBody
with the givensequence
. It supports only onesequence
at present.- Parameters:
sequence
- used to create an instance ofAmqpMessageBody
. A sequence can beList
ofobjects
. Theobject
can be any of the AMQP supported primitive data type.- Returns:
- newly created instance of
AmqpMessageBody
. - Throws:
NullPointerException
- ifsequence
is null.- See Also:
-
fromValue
Creates an instance ofAmqpMessageBody
with 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
- ifvalue
is null.- See Also:
-
getBodyType
Gets theAmqpMessageBodyType
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
Gets anIterableStream
of 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
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
- IfAmqpMessageBodyType
is 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
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
- IfAmqpMessageBodyType
is notDATA
.- See Also:
-
getSequence
Gets the unmodifiable AMQP Sequence set on thisAmqpMessageBody
. It support only onesequence
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
- IfAmqpMessageBodyType
is notSEQUENCE
.- See Also:
-
getValue
Gets the AMQP value set on thisAmqpMessageBody
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
- IfAmqpMessageBodyType
is notVALUE
.- See Also:
-