public final class AmqpMessageBody extends Object
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(newString
(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 newRuntimeException
(String
.format(Locale
.US, "Body type [%s] is not valid.", bodyType)); }
Modifier and Type | Method and Description |
---|---|
static AmqpMessageBody |
fromData(byte[] data)
Creates instance of
AmqpMessageBody with given byte array. |
static AmqpMessageBody |
fromSequence(List<Object> sequence)
Creates an instance of
AmqpMessageBody with the given sequence . |
static AmqpMessageBody |
fromValue(Object value)
Creates an instance of
AmqpMessageBody with the given value . |
AmqpMessageBodyType |
getBodyType()
Gets the
AmqpMessageBodyType of the message. |
IterableStream<byte[]> |
getData()
Gets an
IterableStream of byte array containing only first byte array set on this
AmqpMessageBody . |
byte[] |
getFirstData()
Gets first byte array set on this
AmqpMessageBody . |
List<Object> |
getSequence()
Gets the unmodifiable AMQP Sequence set on this
AmqpMessageBody . |
Object |
getValue()
Gets the AMQP value set on this
AmqpMessageBody instance. |
public static AmqpMessageBody fromData(byte[] data)
AmqpMessageBody
with given byte array.data
- used to create another instance of AmqpMessageBody
.NullPointerException
- if data
is null.public static AmqpMessageBody fromSequence(List<Object> sequence)
AmqpMessageBody
with the given sequence
. It supports only one
sequence
at present.sequence
- used to create an instance of AmqpMessageBody
. A sequence can be List
of
objects
. The object
can be any of the AMQP supported primitive data type.AmqpMessageBody
.NullPointerException
- if sequence
is null.public static AmqpMessageBody fromValue(Object value)
AmqpMessageBody
with the given value
. A value can be any of the
AMQP supported primitive data type.value
- used to create an instance of AmqpMessageBody
.AmqpMessageBody
.NullPointerException
- if value
is null.public AmqpMessageBodyType getBodyType()
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(newString
(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 newRuntimeException
(String
.format(Locale
.US, "Body type [%s] is not valid.", bodyType)); }
public IterableStream<byte[]> getData()
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(newString
(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 newRuntimeException
(String
.format(Locale
.US, "Body type [%s] is not valid.", bodyType)); }
AmqpMessageBody
.IllegalArgumentException
- If AmqpMessageBodyType
is not DATA
.public byte[] getFirstData()
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(newString
(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 newRuntimeException
(String
.format(Locale
.US, "Body type [%s] is not valid.", bodyType)); }
AmqpMessageBody
.IllegalArgumentException
- If AmqpMessageBodyType
is not DATA
.public List<Object> getSequence()
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(newString
(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 newRuntimeException
(String
.format(Locale
.US, "Body type [%s] is not valid.", bodyType)); }
AmqpMessageBody
instance.IllegalArgumentException
- If AmqpMessageBodyType
is not
SEQUENCE
.public Object getValue()
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(newString
(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 newRuntimeException
(String
.format(Locale
.US, "Body type [%s] is not valid.", bodyType)); }
AmqpMessageBody
instance.IllegalArgumentException
- If AmqpMessageBodyType
is not VALUE
.Copyright © 2021 Microsoft Corporation. All rights reserved.