Class AbstractAzureMessageConverter<I,O>
java.lang.Object
com.azure.spring.messaging.converter.AbstractAzureMessageConverter<I,O>
- All Implemented Interfaces:
AzureMessageConverter<I,
O>
public abstract class AbstractAzureMessageConverter<I,O>
extends Object
implements AzureMessageConverter<I,O>
Abstract class handles common conversion logic between <T> and
Message
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuildCustomHeaders
(I azureMessage) Build custom headers from messages received from brokers.protected abstract O
fromByte
(byte[] payload) Build an Azure message from the SpringMessage
's payload, when the payload is a byte array.fromMessage
(org.springframework.messaging.Message<?> message, Class<O> targetClass) Convert the payload of aMessage
from a serialized form to a typed Object of the specified target class.protected <U> U
fromPayload
(Object payload, Class<U> payloadType) Convert payload from byte array to object.protected abstract O
fromString
(String payload) Build an Azure message from the SpringMessage
's payload, when the payload is a String.protected abstract ObjectMapper
Get the object mapper.protected abstract Object
getPayload
(I azureMessage) Get the payload of the received Azure message.protected <U> org.springframework.messaging.Message<?>
Convert the message received from Azure service to SpringMessage
according to the target payload class.protected void
setCustomHeaders
(org.springframework.messaging.MessageHeaders headers, O azureMessage) Set the custom headers for messages to be sent to different brokers.<U> org.springframework.messaging.Message<U>
Create aMessage
whose payload is the result of converting the given payload Object to serialized form.protected byte[]
Convert payload object to byte array.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.azure.spring.messaging.converter.AzureMessageConverter
toMessage
-
Constructor Details
-
AbstractAzureMessageConverter
public AbstractAzureMessageConverter()
-
-
Method Details
-
getObjectMapper
Get the object mapper.- Returns:
- the object mapper.
-
toPayload
Convert payload object to byte array.- Parameters:
object
- The payload object.- Returns:
- The byte array.
- Throws:
ConversionException
- When fail to convert the object to bytes.
-
fromPayload
Convert payload from byte array to object.- Type Parameters:
U
- The type class.- Parameters:
payload
- The payload byte array.payloadType
- The target type of payload.- Returns:
- The converted object.
- Throws:
ConversionException
- When fail to convert to object from byte array.
-
fromMessage
public O fromMessage(@NonNull org.springframework.messaging.Message<?> message, @NonNull Class<O> targetClass) Description copied from interface:AzureMessageConverter
Convert the payload of aMessage
from a serialized form to a typed Object of the specified target class.- Specified by:
fromMessage
in interfaceAzureMessageConverter<I,
O> - Parameters:
message
- the input messagetargetClass
- the target class for the conversion- Returns:
- the result of the conversion, or
null
if the converter cannot perform the conversion
-
toMessage
public <U> org.springframework.messaging.Message<U> toMessage(@NonNull I azureMessage, Map<String, Object> headers, @NonNull Class<U> targetPayloadClass) Description copied from interface:AzureMessageConverter
Create aMessage
whose payload is the result of converting the given payload Object to serialized form. The optionalMessageHeaders
parameter may contain additional headers to be added to the message.- Specified by:
toMessage
in interfaceAzureMessageConverter<I,
O> - Type Parameters:
U
- payload class type in message- Parameters:
azureMessage
- the Object to convertheaders
- optional headers for the messagetargetPayloadClass
- the target payload class for the conversion- Returns:
- the new message, or
null
if the converter does not support the Object type or the target media type
-
getPayload
Get the payload of the received Azure message.- Parameters:
azureMessage
- the received Azure message.- Returns:
- message payload.
-
fromString
Build an Azure message from the SpringMessage
's payload, when the payload is a String.- Parameters:
payload
- the String payload.- Returns:
- the Azure message.
-
fromByte
Build an Azure message from the SpringMessage
's payload, when the payload is a byte array.- Parameters:
payload
- the byte array payload.- Returns:
- the Azure message.
-
setCustomHeaders
protected void setCustomHeaders(org.springframework.messaging.MessageHeaders headers, O azureMessage) Set the custom headers for messages to be sent to different brokers.- Parameters:
headers
- the custom headers.azureMessage
- the message to be sent.
-
buildCustomHeaders
Build custom headers from messages received from brokers.- Parameters:
azureMessage
- the received Azure message.- Returns:
- the headers.
-
internalToMessage
protected <U> org.springframework.messaging.Message<?> internalToMessage(I azureMessage, Map<String, Object> headers, Class<U> targetPayloadClass) Convert the message received from Azure service to SpringMessage
according to the target payload class.- Type Parameters:
U
- the target payload class.- Parameters:
azureMessage
- the message received from Azure serviceheaders
- the headers built from the received Azure message.targetPayloadClass
- the target payload class.- Returns:
- the converted Spring message.
-