public final class AmqpMessageBody extends Object
AmqpMessageBodyType map to an AMQP specification message
body types. Current implementation only support DATA AMQP data type. Track this
issue to find out support for
other AMQP types.
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
// If client do not check `AmqpMessageBody.getBodyType()` and payload is not of type `AmqpMessageBodyType.DATA`,
// calling `getFirstData()` or `getData()` on `AmqpMessageBody` will throw Runtime exception.
// https://github.com/Azure/azure-sdk-for-java/issues/17614 : This issue tracks additional AMQP body type
// support in future.
byte[] payload = null;
AmqpMessageBodyType bodyType = amqpAnnotatedMessage.getBody().getBodyType();
switch (bodyType) {
case DATA:
payload = amqpAnnotatedMessage.getBody().getFirstData();
break;
case SEQUENCE:
case VALUE:
throw new RuntimeException("Body type not supported yet.");
default:
throw new RuntimeException("Body type not valid.");
}
System.out.println(new String(payload));
AmqpMessageBodyType| Modifier and Type | Method and Description |
|---|---|
static AmqpMessageBody |
fromData(byte[] data)
Creates instance of
AmqpMessageBody with given byte array. |
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. |
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 AmqpMessageBodyType getBodyType()
AmqpMessageBodyType of the message.
How to check for AmqpMessageBodyType
// If client do not check `AmqpMessageBody.getBodyType()` and payload is not of type `AmqpMessageBodyType.DATA`,
// calling `getFirstData()` or `getData()` on `AmqpMessageBody` will throw Runtime exception.
// https://github.com/Azure/azure-sdk-for-java/issues/17614 : This issue tracks additional AMQP body type
// support in future.
byte[] payload = null;
AmqpMessageBodyType bodyType = amqpAnnotatedMessage.getBody().getBodyType();
switch (bodyType) {
case DATA:
payload = amqpAnnotatedMessage.getBody().getFirstData();
break;
case SEQUENCE:
case VALUE:
throw new RuntimeException("Body type not supported yet.");
default:
throw new RuntimeException("Body type not valid.");
}
System.out.println(new String(payload));
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
// If client do not check `AmqpMessageBody.getBodyType()` and payload is not of type `AmqpMessageBodyType.DATA`,
// calling `getFirstData()` or `getData()` on `AmqpMessageBody` will throw Runtime exception.
// https://github.com/Azure/azure-sdk-for-java/issues/17614 : This issue tracks additional AMQP body type
// support in future.
byte[] payload = null;
AmqpMessageBodyType bodyType = amqpAnnotatedMessage.getBody().getBodyType();
switch (bodyType) {
case DATA:
payload = amqpAnnotatedMessage.getBody().getFirstData();
break;
case SEQUENCE:
case VALUE:
throw new RuntimeException("Body type not supported yet.");
default:
throw new RuntimeException("Body type not valid.");
}
System.out.println(new String(payload));
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
// If client do not check `AmqpMessageBody.getBodyType()` and payload is not of type `AmqpMessageBodyType.DATA`,
// calling `getFirstData()` or `getData()` on `AmqpMessageBody` will throw Runtime exception.
// https://github.com/Azure/azure-sdk-for-java/issues/17614 : This issue tracks additional AMQP body type
// support in future.
byte[] payload = null;
AmqpMessageBodyType bodyType = amqpAnnotatedMessage.getBody().getBodyType();
switch (bodyType) {
case DATA:
payload = amqpAnnotatedMessage.getBody().getFirstData();
break;
case SEQUENCE:
case VALUE:
throw new RuntimeException("Body type not supported yet.");
default:
throw new RuntimeException("Body type not valid.");
}
System.out.println(new String(payload));
AmqpMessageBody.IllegalArgumentException - If AmqpMessageBodyType is not DATA.Copyright © 2021 Microsoft Corporation. All rights reserved.