Enum DeserializationFailurePolicy

java.lang.Object
java.lang.Enum<DeserializationFailurePolicy>
io.github.flink.gcp.connector.pubsub.source.DeserializationFailurePolicy
All Implemented Interfaces:
Serializable, Comparable<DeserializationFailurePolicy>, java.lang.constant.Constable

@Public public enum DeserializationFailurePolicy extends Enum<DeserializationFailurePolicy>
What the source does with a message its deserialization schema cannot convert.

Set via PubSubSourceBuilder.deserializationFailurePolicy(DeserializationFailurePolicy). Whichever is chosen, the failure is counted in Flink's standard numRecordsInErrors metric.

toString() returns the lower-case spelling rather than the constant name, because that spelling is what a SQL WITH clause is written in: Flink resolves an enum ConfigOption by matching the configured value against toString(), case-insensitively and with no other normalization. Flink's own DeliveryGuarantee carries its option spelling the same way.

  • Enum Constant Details

    • FAIL

      public static final DeserializationFailurePolicy FAIL
      Fails the job. The message stays unacknowledged, so Pub/Sub redelivers it — which means a message that can never be deserialized fails the job again after every restart until it is removed or the schema is fixed. That is the default because silently discarding data should be a decision, not an accident.
    • DROP

      public static final DeserializationFailurePolicy DROP
      Discards the message and carries on, acknowledging it immediately so it is not redelivered. Failures are counted and logged at a decreasing rate, so a burst of bad messages does not flood the log.

      This drops data. A schema that collected records before failing keeps those — the emitted prefix has already reached the output and cannot be recalled — so a partial message is discarded partially.

    • NACK

      public static final DeserializationFailurePolicy NACK
      Returns the message to Pub/Sub for redelivery and carries on, leaving what to do with it to the subscription's dead-letter policy: each redelivery raises the message's delivery attempt count until Pub/Sub forwards it to the dead-letter topic.

      Requires a dead-letter policy on every subscription, which the source checks at startup and refuses to run without. Nacking does not fail the job, so without one a message the schema can never convert is redelivered forever, invisibly.

      Dead-lettering counts deliveries rather than causes, so an unrelated job restart raises the same counter: set the subscription's delivery-attempt limit high enough that ordinary failovers do not dead-letter healthy messages.

      Like DROP, a schema that emitted records before failing keeps those, so the message is both partially emitted and redelivered in full.

  • Method Details

    • values

      public static DeserializationFailurePolicy[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static DeserializationFailurePolicy valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • toString

      public String toString()
      Overrides:
      toString in class Enum<DeserializationFailurePolicy>
    • requiresDeadLetterPolicy

      public boolean requiresDeadLetterPolicy()
      Returns whether this policy needs a dead-letter policy on the subscription, which the source checks at startup.

      A property of the policy rather than a comparison at the call site, because the constraint belongs next to the constant that creates it: a future policy that nacks has to answer this, and the check two packages away would otherwise silently let it through. What makes a nack need one is not the nack but the job surviving it — the message comes back and fails again forever. The reader also nacks when emitting a message downstream fails, and that one needs nothing behind it because it rethrows and the job fails visibly.