Interface CloudEventBuilder

All Superinterfaces:
io.cloudevents.rw.CloudEventContextWriter, io.cloudevents.rw.CloudEventWriter<io.cloudevents.CloudEvent>
All Known Implementing Classes:
BaseCloudEventBuilder, CloudEventBuilder, CloudEventBuilder

@ParametersAreNullableByDefault public interface CloudEventBuilder extends io.cloudevents.rw.CloudEventWriter<io.cloudevents.CloudEvent>
Builder interface to build a CloudEvent.
  • Method Details

    • withId

      Set the id of the event
      Parameters:
      id - id of the event
      Returns:
      self
    • withSource

      CloudEventBuilder withSource(URI source)
      Set the source of the event
      Parameters:
      source - source of the event
      Returns:
      self
    • withType

      CloudEventBuilder withType(String type)
      Set the type of the event
      Parameters:
      type - type of the event
      Returns:
      self
    • withDataSchema

      CloudEventBuilder withDataSchema(URI dataSchema)
      Set the dataschema of the event. For CloudEvent v0.3, this will configure the schemaurl attribute.
      Parameters:
      dataSchema - dataschema of the event
      Returns:
      self
    • withDataContentType

      CloudEventBuilder withDataContentType(String dataContentType)
      Set the datacontenttype of the event
      Parameters:
      dataContentType - datacontenttype of the event
      Returns:
      self
    • withSubject

      CloudEventBuilder withSubject(String subject)
      Set the subject of the event
      Parameters:
      subject - subject of the event
      Returns:
      self
    • withTime

      Set the time of the event
      Parameters:
      time - time of the event
      Returns:
      self
    • withData

      CloudEventBuilder withData(byte[] data)
      Set the data of the event
      Parameters:
      data - data of the event
      Returns:
      self
    • withData

      CloudEventBuilder withData(String dataContentType, byte[] data)
      Set the datacontenttype and data of the event
      Parameters:
      dataContentType - datacontenttype of the event
      data - data of the event
      Returns:
      self
    • withData

      CloudEventBuilder withData(String dataContentType, URI dataSchema, byte[] data)
      Set the datacontenttype, dataschema and data of the event
      Parameters:
      dataContentType - datacontenttype of the event
      dataSchema - dataschema of the event
      data - data of the event
      Returns:
      self
    • withData

      CloudEventBuilder withData(io.cloudevents.CloudEventData data)
      Set the data of the event
      Parameters:
      data - data of the event
      Returns:
      self
    • withData

      CloudEventBuilder withData(String dataContentType, io.cloudevents.CloudEventData data)
      Set the datacontenttype and data of the event
      Parameters:
      dataContentType - datacontenttype of the event
      data - data of the event
      Returns:
      self
    • withData

      CloudEventBuilder withData(String dataContentType, URI dataSchema, io.cloudevents.CloudEventData data)
      Set the datacontenttype, dataschema and data of the event
      Parameters:
      dataContentType - datacontenttype of the event
      dataSchema - dataschema of the event
      data - data of the event
      Returns:
      self
    • withoutData

      CloudEventBuilder withoutData()
      Remove the datacontenttype, dataschema and data from the event
      Returns:
      self
    • withoutDataSchema

      CloudEventBuilder withoutDataSchema()
      Remove the dataschema from the event
      Returns:
      self
    • withoutDataContentType

      CloudEventBuilder withoutDataContentType()
      Remove the datacontenttype from the event
      Returns:
      self
    • withExtension

      CloudEventBuilder withExtension(@Nonnull String key, @Nonnull String value)
      Set an extension with provided key and string value
      Parameters:
      key - key of the extension attribute
      value - value of the extension attribute
      Returns:
      self
    • withExtension

      CloudEventBuilder withExtension(@Nonnull String key, @Nonnull Number value)
      Set an extension with provided key and numeric value
      Parameters:
      key - key of the extension attribute
      value - value of the extension attribute
      Returns:
      self
    • withExtension

      CloudEventBuilder withExtension(@Nonnull String key, @Nonnull Boolean value)
      Set an extension with provided key and boolean value
      Parameters:
      key - key of the extension attribute
      value - value of the extension attribute
      Returns:
      self
    • withExtension

      CloudEventBuilder withExtension(@Nonnull String key, @Nonnull URI value)
      Set an extension with provided key and uri value
      Parameters:
      key - key of the extension attribute
      value - value of the extension attribute
      Returns:
      self
    • withExtension

      CloudEventBuilder withExtension(@Nonnull String key, @Nonnull OffsetDateTime value)
      Set an extension with provided key and boolean value
      Parameters:
      key - key of the extension attribute
      value - value of the extension attribute
      Returns:
      self
    • withExtension

      CloudEventBuilder withExtension(@Nonnull String key, @Nonnull byte[] value)
      Set an extension with provided key and binary value
      Parameters:
      key - key of the extension attribute
      value - value of the extension attribute
      Returns:
      self
    • withExtension

      CloudEventBuilder withExtension(@Nonnull io.cloudevents.CloudEventExtension extension)
      Add to the builder all the extension key/values of the provided extension
      Parameters:
      extension - materialized extension to set in the builder
      Returns:
      self
    • withoutExtension

      CloudEventBuilder withoutExtension(@Nonnull String key)
      Remove from the the builder the provided extension key, if any
      Parameters:
      key - key of the extension attribute
      Returns:
      self
    • withoutExtension

      CloudEventBuilder withoutExtension(@Nonnull io.cloudevents.CloudEventExtension extension)
      Remove from the the builder the provided extension, if any
      Parameters:
      extension - materialized extension to remove from the builder
      Returns:
      self
    • build

      io.cloudevents.CloudEvent build() throws IllegalStateException
      Build the event
      Returns:
      the built event
      Throws:
      IllegalStateException - if a required attribute is not configured
    • newBuilder

      CloudEventBuilder newBuilder()
      Copy this builder, creating a new instance with same values.
      Returns:
      A new builder with same values of this instance
    • v1

      static CloudEventBuilder v1()
      Returns:
      a new CloudEvent v1 builder
    • v1

      static CloudEventBuilder v1(@Nonnull io.cloudevents.CloudEvent event)
      Parameters:
      event - event to bootstrap the builder
      Returns:
      a new CloudEvent v1 builder filled with content of event
    • v03

      static CloudEventBuilder v03()
      Returns:
      a new CloudEvent v0.3 builder
    • v03

      static CloudEventBuilder v03(@Nonnull io.cloudevents.CloudEvent event)
      Parameters:
      event - event to bootstrap the builder
      Returns:
      a new CloudEvent v0.3 builder filled with content of event
    • fromSpecVersion

      static CloudEventBuilder fromSpecVersion(@Nonnull io.cloudevents.SpecVersion version)
      Create a new builder for the specified SpecVersion
      Parameters:
      version - version to use for the new builder
      Returns:
      a new builder
    • from

      static CloudEventBuilder from(@Nonnull io.cloudevents.CloudEvent event)
      Create a new builder starting from the values of the provided event.
      Parameters:
      event - event to copy values from
      Returns:
      the new builder
    • fromContext

      static CloudEventBuilder fromContext(@Nonnull io.cloudevents.CloudEventContext context)
      Create a new builder starting from the values of the provided context.
      Parameters:
      context - context to copy values from
      Returns:
      the new builder