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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Map<String,Object>
    buildCustomHeaders(I azureMessage)
    Build custom headers from messages received from brokers.
    protected abstract O
    fromByte(byte[] payload)
    Build an Azure message from the Spring Message's payload, when the payload is a byte array.
    fromMessage(org.springframework.messaging.Message<?> message, Class<O> targetClass)
    Convert the payload of a Message 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 Spring Message'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<?>
    internalToMessage(I azureMessage, Map<String,Object> headers, Class<U> targetPayloadClass)
    Convert the message received from Azure service to Spring Message 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>
    toMessage(I azureMessage, Map<String,Object> headers, Class<U> targetPayloadClass)
    Create a Message whose payload is the result of converting the given payload Object to serialized form.
    protected byte[]
    toPayload(Object object)
    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

      protected abstract ObjectMapper getObjectMapper()
      Get the object mapper.
      Returns:
      the object mapper.
    • toPayload

      protected byte[] toPayload(Object object)
      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

      protected <U> U fromPayload(Object payload, Class<U> payloadType)
      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 a Message from a serialized form to a typed Object of the specified target class.
      Specified by:
      fromMessage in interface AzureMessageConverter<I,O>
      Parameters:
      message - the input message
      targetClass - 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 a Message whose payload is the result of converting the given payload Object to serialized form. The optional MessageHeaders parameter may contain additional headers to be added to the message.
      Specified by:
      toMessage in interface AzureMessageConverter<I,O>
      Type Parameters:
      U - payload class type in message
      Parameters:
      azureMessage - the Object to convert
      headers - optional headers for the message
      targetPayloadClass - 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

      protected abstract Object getPayload(I azureMessage)
      Get the payload of the received Azure message.
      Parameters:
      azureMessage - the received Azure message.
      Returns:
      message payload.
    • fromString

      protected abstract O fromString(String payload)
      Build an Azure message from the Spring Message's payload, when the payload is a String.
      Parameters:
      payload - the String payload.
      Returns:
      the Azure message.
    • fromByte

      protected abstract O fromByte(byte[] payload)
      Build an Azure message from the Spring Message'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

      protected Map<String,Object> buildCustomHeaders(I azureMessage)
      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 Spring Message according to the target payload class.
      Type Parameters:
      U - the target payload class.
      Parameters:
      azureMessage - the message received from Azure service
      headers - the headers built from the received Azure message.
      targetPayloadClass - the target payload class.
      Returns:
      the converted Spring message.