Class CloudEvent<T>

  • Type Parameters:
    T - The type of the payload.

    public class CloudEvent<T>
    extends Object
    A cloud event in Dapr.
    • Field Detail

      • OBJECT_MAPPER

        protected static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPER
        Shared Json serializer/deserializer as per Jackson's documentation.
    • Constructor Detail

      • CloudEvent

        public CloudEvent()
        Instantiates a CloudEvent.
      • CloudEvent

        public CloudEvent​(String id,
                          String source,
                          String type,
                          String specversion,
                          String datacontenttype,
                          T data)
        Instantiates a CloudEvent.
        Parameters:
        id - Identifier of the message being processed.
        source - Source for this event.
        type - Type of event.
        specversion - Version of the event spec.
        datacontenttype - Type of the payload.
        data - Payload.
      • CloudEvent

        public CloudEvent​(String id,
                          String source,
                          String type,
                          String specversion,
                          byte[] binaryData)
        Instantiates a CloudEvent.
        Parameters:
        id - Identifier of the message being processed.
        source - Source for this event.
        type - Type of event.
        specversion - Version of the event spec.
        binaryData - Payload.
    • Method Detail

      • deserialize

        public static CloudEvent<?> deserialize​(byte[] payload)
                                         throws IOException
        Deserialize a message topic from Dapr.
        Parameters:
        payload - Payload sent from Dapr.
        Returns:
        Message (can be null if input is null)
        Throws:
        IOException - If cannot parse.
      • getId

        public String getId()
        Gets the identifier of the message being processed.
        Returns:
        Identifier of the message being processed.
      • setId

        public void setId​(String id)
        Sets the identifier of the message being processed.
        Parameters:
        id - Identifier of the message being processed.
      • getSource

        public String getSource()
        Gets the event's source.
        Returns:
        Event's source.
      • setSource

        public void setSource​(String source)
        Sets the event's source.
        Parameters:
        source - Event's source.
      • getType

        public String getType()
        Gets the envelope type.
        Returns:
        Envelope type.
      • setType

        public void setType​(String type)
        Sets the envelope type.
        Parameters:
        type - Envelope type.
      • getSpecversion

        public String getSpecversion()
        Gets the version of the specification.
        Returns:
        Version of the specification.
      • setSpecversion

        public void setSpecversion​(String specversion)
        Sets the version of the specification.
        Parameters:
        specversion - Version of the specification.
      • getDatacontenttype

        public String getDatacontenttype()
        Gets the type of the data's content.
        Returns:
        Type of the data's content.
      • setDatacontenttype

        public void setDatacontenttype​(String datacontenttype)
        Sets the type of the data's content.
        Parameters:
        datacontenttype - Type of the data's content.
      • getData

        public T getData()
        Gets the cloud event data.
        Returns:
        Cloud event's data. As per specs, data can be a JSON object or string.
      • setData

        public void setData​(T data)
        Sets the cloud event data. As per specs, data can be a JSON object or string.
        Parameters:
        data - Cloud event's data. As per specs, data can be a JSON object or string.
      • getBinaryData

        public byte[] getBinaryData()
        Gets the cloud event's binary data.
        Returns:
        Cloud event's binary data.
      • setBinaryData

        public void setBinaryData​(byte[] binaryData)
        Sets the cloud event's binary data.
        Parameters:
        binaryData - Cloud event's binary data.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object