Unbind consumers after binding startup failure
Spring Cloud Stream accepted the binding-startup cleanup fix through maintainer commit 5a2c800, preserving authorship and sign-off while closing the partial-startup failure issue.
spring-cloud/spring-cloud-stream · #3207
Problem
With binding-retry-interval=0 and Kafka auto-create-topics disabled, a missing topic could make one consumer binding fail while earlier bindings stayed active. The application stayed partially initialized, consumed messages on healthy topics, then dropped them because the context was not ready for dispatch or error-channel routing.
Approach
Tracked bindables and consumer bindings started before a failure, stopped and unbound them when later startup work failed, and attached cleanup failures as suppressed exceptions before rethrowing the original startup failure.
Impact and scope
- Restores the strict startup guarantee expected when binding-retry-interval=0 is used in production-style Spring Cloud Stream deployments.
- Prevents partial consumer activation that can advance Kafka offsets while user code never receives the message.
- Improves lifecycle hygiene by cleaning up already-started bindables and multi-target consumer bindings after startup failure.
Validation
- Added BindingLifecycleTests coverage proving started bindables are unbound when a later bindable fails during lifecycle startup.
- Added BindingServiceTests coverage proving earlier consumer bindings are stopped and unbound if a later target in a multi-destination binding fails.
- PR validation included focused BindingLifecycleTests and BindingServiceTests plus the core spring-cloud-stream module test run.