Handling Delivery Failure

You can configure event delivery parameters for Knative Eventing components that are applied in cases where an event fails to be delivered

Configuring Subscription event delivery

You can configure how events are delivered for each Subscription by adding a delivery spec to the Subscription object, as shown in the following example:

  1. apiVersion: messaging.knative.dev/v1
  2. kind: Subscription
  3. metadata:
  4. name: example-subscription
  5. namespace: example-namespace
  6. spec:
  7. delivery:
  8. deadLetterSink:
  9. ref:
  10. apiVersion: serving.knative.dev/v1
  11. kind: Service
  12. name: example-sink
  13. backoffDelay: <duration>
  14. backoffPolicy: <policy-type>
  15. retry: <integer>

Where

  • The deadLetterSink spec contains configuration settings to enable using a dead letter sink. This tells the Subscription what happens to events that cannot be delivered to the subscriber. When this is configured, events that fail to be delivered are sent to the dead letter sink destination. The destination can be a Knative Service or a URI. In the example, the destination is a Service object, or Knative Service, named example-sink.
  • The backoffDelay delivery parameter specifies the time delay before an event delivery retry is attempted after a failure. The duration of the backoffDelay parameter is specified using the ISO 8601 format. For example, PT1S specifies a 1 second delay.
  • The backoffPolicy delivery parameter can be used to specify the retry back off policy. The policy can be specified as either linear or exponential. When using the linear back off policy, the back off delay is the time interval specified between retries. When using the exponential back off policy, the back off delay is equal to backoffDelay*2^<numberOfRetries>.
  • retry specifies the number of times that event delivery is retried before the event is sent to the dead letter sink.

Configuring Broker event delivery

You can configure how events are delivered for each Broker by adding a delivery spec, as shown in the following example:

  1. apiVersion: eventing.knative.dev/v1
  2. kind: Broker
  3. metadata:
  4. name: with-dead-letter-sink
  5. spec:
  6. delivery:
  7. deadLetterSink:
  8. ref:
  9. apiVersion: serving.knative.dev/v1
  10. kind: Service
  11. name: example-sink
  12. backoffDelay: <duration>
  13. backoffPolicy: <policy-type>
  14. retry: <integer>

Where

  • The deadLetterSink spec contains configuration settings to enable using a dead letter sink. This tells the Subscription what happens to events that cannot be delivered to the subscriber. When this is configured, events that fail to be delivered are sent to the dead letter sink destination. The destination can be any Addressable object that conforms to the Knative Eventing sink contract, such as a Knative Service, a Kubernetes Service, or a URI. In the example, the destination is a Service object, or Knative Service, named example-sink.
  • The backoffDelay delivery parameter specifies the time delay before an event delivery retry is attempted after a failure. The duration of the backoffDelay parameter is specified using the ISO 8601 format. For example, PT1S specifies a 1 second delay.
  • The backoffPolicy delivery parameter can be used to specify the retry back off policy. The policy can be specified as either linear or exponential. When using the linear back off policy, the back off delay is the time interval specified between retries. This is a linearly increasing delay, which means that the back off delay increases by the given interval for each retry. When using the exponential back off policy, the back off delay increases by a multiplier of the given interval for each retry.
  • retry specifies the number of times that event delivery is retried before the event is sent to the dead letter sink. The initial delivery attempt is not included in the retry count, so the total number of delivery attempts is equal to the retry value +1.

Broker support

The following table summarizes which delivery parameters are supported for each Broker implementation type:

Broker ClassSupported Delivery Parameters
googleclouddeadLetterSink, retry, backoffPolicy, backoffDelay
KafkadeadLetterSink, retry, backoffPolicy, backoffDelay
MTChannelBasedBrokerdepends on the underlying Channel
RabbitMQBrokerdeadLetterSink, retry, backoffPolicy, backoffDelay

Note

deadLetterSink must be a GCP Pub/Sub topic URI.

Note

googlecloud Broker only supports the exponential back off policy.

Configuring Channel event delivery

Failed events may, depending on the specific Channel implementation in use, be enhanced with extension attributes prior to forwarding to thedeadLetterSink. These extension attributes are as follows:

  • knativeerrordest

    • Type: String
    • Description: The original destination URL to which the failed event was sent. This could be either a delivery or reply URL based on which operation encountered the failed event.
    • Constraints: Always present because every HTTP Request has a destination URL.
    • Examples:
  • knativeerrorcode

    • Type: Int
    • Description: The HTTP Response StatusCode from the final event dispatch attempt.
    • Constraints: Always present because every HTTP Response contains a StatusCode.
    • Examples:
      • “500”
      • …any HTTP StatusCode…
  • knativeerrordata

    • Type: String
    • Description: The HTTP Response Body from the final event dispatch attempt.
    • Constraints: Empty if the HTTP Response Body is empty, and may be truncated if the length is excessive.
    • Examples:
      • ‘Internal Server Error: Failed to process event.’
      • ‘{“key”: “value”}’
      • …any HTTP Response Body…

Channel support

The following table summarizes which delivery parameters are supported for each Channel implementation.

Channel TypeSupported Delivery Parameters
GCP PubSubnone
In-MemorydeadLetterSink, retry, backoffPolicy, backoffDelay
KafkadeadLetterSink, retry, backoffPolicy, backoffDelay
Natssnone