Spring Event Hubs: dedicated builder in one section pollutes shared section's EventHubClientBuilder injection
Event HubsService AttentionClientneeds-team-attention
Follow-up to #49076.
### Problem
In `spring-cloud-azure-starter-eventhubs`, `AzureEventHubsClientBuilderConfiguration#eventHubClientBuilder` is `@ConditionalOnMissingBean(EventHubClientBuilder.class)` (type-based). Whenever **either** `AzureEventHubsConsumerClientConfiguration.DedicatedConsumerConnectionConfiguration` or `AzureEventHubsProducerClientConfiguration.DedicatedProducerConnectionConfiguration` activates, it registers a named-but-`EventHubClientBuilder`-typed bean (`springCloudAzureEventHubsConsumerClientBuilder` / `springCloudAzureEventHubsProducerClientBuilder`). That suppresses the root builder.
If the **other** section has no sub-level override, its `SharedConsumer`/`SharedProducerConnectionConfiguration` still activates (its `@ConditionalOnBean(EventHubClientBuilder.class)` is now satisfied by the *dedicated builder from the opposite section*) and Spring resolves the unqualified `EventHubClientBuilder` parameter to that one bean. Result: the shared client targets the *other section's* event hub.
### Repro (after #49076)
```yaml
spring:
cloud:
azure:
eventhubs:
namespace: evhns-sample
event-hub-name: base-hub
consumer:
consumer-group: $Default
event-hub-name: override-hub
```
- Dedicated consumer activates against `override-hub` (correct, fixed by #49076).
- Producer has no sub-level override, so shared producer activates and injects the consumer-dedicated builder, producing against `override-hub` instead of `base-hub`.
The same flaw triggers today (without #49076) when a user sets `consumer.connection-string` or `consumer.namespace` without a producer override (or vice versa); #49076 only extends the trigger to `event-hub-name`.
### Scope
Out of scope for #49076 because the wiring flaw predates that PR. Plausible fixes:
- Name the root builder and switch `@ConditionalOnMissingBean(EventHubClientBuilder.class)` to a name-based check so dedicated builders no longer suppress it.
- Or mark the root `@Primary` (after the above) and add `@Qualifier` to the shared `EventHubClientBuilder` injection points.
- Add regression coverage in `AzureEventHubsConsumer/ProducerClientConfigurationTests` for the asymmetric (one-side dedicated, one-side shared) configuration.
Unaffected: the Spring Messaging template path (`AzureEventHubsMessagingAutoConfiguration` → `NamespaceProperties` → `DefaultEventHubsNamespaceProducerFactory`) does not depend on these client builder beans.
cc @rujche
1 条评论