AmqpMessageBody Class
- java.
lang. Object - com.
azure. core. amqp. models. AmqpMessageBody
- com.
public final class AmqpMessageBody
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));
}
Method Summary
Modifier and Type | Method and Description |
---|---|
static
Amqp |
fromData(byte[] data)
Creates instance of AmqpMessageBody with given byte array. |
static
Amqp |
fromSequence(List<Object> sequence)
Creates an instance of AmqpMessageBody with the given sequence. |
static
Amqp |
fromValue(Object value)
Creates an instance of AmqpMessageBody with the given value. |
Amqp |
getBodyType()
Gets the AmqpMessageBodyType of the message. |
Iterable |
getData()
Gets an IterableStream<T> 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. |
Methods inherited from java.lang.Object
Method Details
fromData
public static AmqpMessageBody fromData(byte[] data)
Creates instance of AmqpMessageBody with given byte array.
Parameters:
Returns:
fromSequence
public static AmqpMessageBody fromSequence(List
Creates an instance of AmqpMessageBody with the given sequence. It supports only one sequence
at present.
Parameters:
Returns:
fromValue
public static AmqpMessageBody fromValue(Object value)
Creates an instance of AmqpMessageBody with the given value. A value can be any of the AMQP supported primitive data type.
Parameters:
Returns:
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:
getData
public IterableStream
Gets an IterableStream<T> 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:
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:
getSequence
public List
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:
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:
Applies to
Azure SDK for Java
Comentarios
https://aka.ms/ContentUserFeedback.
Próximamente: A lo largo de 2024 iremos eliminando gradualmente GitHub Issues como mecanismo de comentarios sobre el contenido y lo sustituiremos por un nuevo sistema de comentarios. Para más información, vea:Enviar y ver comentarios de