Class FailedMessage

java.lang.Object
io.github.flink.gcp.connector.pubsub.sink.FailedMessage
All Implemented Interfaces:
FailedElement

@Public public final class FailedMessage extends Object implements FailedElement
A single message that terminally failed to be published to Pub/Sub, as passed to a FailureHandler<FailedMessage>.

Carries the PubsubMessage the serializer produced rather than the original record: the sink writer is stateless and retains only serialized messages, so by the time a publish is rejected the original record object no longer exists. When serialization itself failed, getPubsubMessage() is null.

getPayloadBytes() is the whole serialized message, not just its data, so the attributes and the ordering key survive a dead-letter round trip: a consumer recovers them with PubsubMessage.parseFrom(bytes).

Instances are created by the sink and are not serializable.

  • Method Details

    • of

      public static FailedMessage of(TopicDestination destination, @Nullable com.google.pubsub.v1.PubsubMessage message, String errorMessage, @Nullable Throwable cause)
      Creates a failed message. Intended for the sink implementation (and tests of custom handlers).
      Parameters:
      destination - the topic the message was routed to
      message - the serialized message, or null when serialization itself failed
      errorMessage - the failure description
      cause - the underlying failure, or null
      Returns:
      the failed message
    • getDestination

      public TopicDestination getDestination()
      Returns the topic the message was routed to.
    • getPubsubMessage

      @Nullable public com.google.pubsub.v1.PubsubMessage getPubsubMessage()
      Returns the message the serializer produced, or null when the record could not be serialized in the first place.
    • getConnector

      public String getConnector()
      Description copied from interface: FailedElement
      Returns the connector that produced the failure, as a lower-case identifier ( "bigquery", "bigtable", "cloudtasks", "pubsub", "spanner") — stable, so dead-letter consumers can key on it.
      Specified by:
      getConnector in interface FailedElement
    • describeDestination

      public String describeDestination()
      Returns the topic in the projects/<p>/topics/<t> form.
      Specified by:
      describeDestination in interface FailedElement
    • getPayloadBytes

      @Nullable public com.google.protobuf.ByteString getPayloadBytes()
      Returns the serialized PubsubMessage — payload, attributes and ordering key alike — or null when serialization itself failed.
      Specified by:
      getPayloadBytes in interface FailedElement
    • getErrorMessage

      public String getErrorMessage()
      Description copied from interface: FailedElement
      Returns the failure description. It is always present, even when FailedElement.getCause() is null, and it is the detail that FailureHandler.failJob() raises and FailureHandler.logAndDrop() logs.
      Specified by:
      getErrorMessage in interface FailedElement
    • getCause

      @Nullable public Throwable getCause()
      Description copied from interface: FailedElement
      Returns the underlying failure, or null when none is available.
      Specified by:
      getCause in interface FailedElement
    • toString

      public String toString()
      Overrides:
      toString in class Object