Class FromCloudEventTransformer

All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, InitializingBean, ApplicationContextAware, ComponentSourceAware, ExpressionCapable, GenericTransformer<Message<?>, Message<?>>, NamedComponent, Transformer

public class FromCloudEventTransformer extends AbstractTransformer
Transform CloudEvent format messages to Spring Integration messages.

This transformer supports two payload types:

  • CloudEvent Object Type: When the message payload is a CloudEvent instance, the transformer extracts the CloudEvent data from the message payload and maps CloudEvent attributes to message headers using CloudEventHeaders constants. CloudEvent extensions are also mapped to message headers with the "ce-" prefix.
  • Serialized CloudEvent Type: When the message payload is a byte[] containing a serialized CloudEvent (e.g., JSON, XML), the transformer uses the MessageHeaders.CONTENT_TYPE header to resolve an EventFormat via EventFormatProvider. If the EventFormat is not found from the MessageHeaders.CONTENT_TYPE or if the message does not contain MessageHeaders.CONTENT_TYPE then it will fall back to the setEventFormat(EventFormat). The CloudEvent is then deserialized, and the data is extracted from the CloudEvent with its attributes mapped to headers.
Since:
7.1
Author:
Glenn Renfro, Artem Bilan
See Also:
  • Constructor Details

    • FromCloudEventTransformer

      public FromCloudEventTransformer()
  • Method Details

    • setEventFormat

      public void setEventFormat(io.cloudevents.core.format.EventFormat eventFormat)
      Establish the EventFormat that will be used if the EventFormatProvider can not identify the EventFormat for the MessageHeaders.CONTENT_TYPE or the message does not contain a MessageHeaders.CONTENT_TYPE.
      Parameters:
      eventFormat - The fallback EventFormat to use if EventFormatProvider can not identify the EventFormat for the payload.
    • getComponentType

      public String getComponentType()
    • doTransform

      protected Object doTransform(Message<?> message)
      Description copied from class: AbstractTransformer
      Subclasses must implement this method to provide the transformation logic. If the return value is itself a Message, it will be used as the result. Otherwise, any non-null return value will be used as the payload of the result Message.
      Specified by:
      doTransform in class AbstractTransformer
      Parameters:
      message - The message.
      Returns:
      The result of the transformation.