Skip to content

[BUG] The base level event-hub-name property should be overridden when sub-level event-hub-name property configured #43593

@haoozhang

Description

@haoozhang

Describe the bug

When using the spring-cloud-azure-starter-eventhubs dependency, if I specify the properties in the application.yaml as follows, I think the expected result is that the event-hub-name in the producer and consumer section will override the base event-hub-name, that is, the application will eventually use the aaaa event hub, not bbbb.

spring:
  cloud:
    azure:
      eventhubs:
        namespace: evhns-sample
        event-hub-name: bbbb
        consumer:
          consumer-group: $Default
          event-hub-name: aaaa
        producer:
          event-hub-name: aaaa

But for the following code,

    @Autowired
    private EventHubConsumerClient consumerClient;

    @Autowired
    private EventHubProducerClient producerClient;
    
    @Override
    public void run(String... args) throws Exception {
        LOGGER.info("Sending message using Event Hub producer client. ==> {}", producerClient.getEventHubName());
        producerClient.send(Arrays.asList(new EventData("Test event")));
        LOGGER.info("Sent message to Event Hub.");
        producerClient.close();

        TimeUnit.SECONDS.sleep(3);
        LOGGER.info("Receiving message using Event Hub consumer client. ==> {}", consumerClient.getEventHubName());
        String PARTITION_ID = "0";
        IterableStream<PartitionEvent> partitionEvents = consumerClient.receiveFromPartition(PARTITION_ID, 1,
            EventPosition.earliest());
        Iterator<PartitionEvent> iterator = partitionEvents.stream().iterator();
        if (iterator.hasNext()) {
            PartitionEvent pe = iterator.next();
            LOGGER.info("Received message: {}", pe.getData().getBodyAsString());
        } else {
            LOGGER.error("Failed to receive message.");
        }
    }

The application logs show that it still use bbbb, not the aaaa, which is inconsistent as above expectation.

Sending message using Event Hub producer client. ==> bbbb
....
Receiving message using Event Hub consumer client. ==> bbbb

Exception or Stack Trace
No exception, just inconsistent behavior.

To Reproduce
Steps to reproduce the behavior:

Run this repo code: https://github.com/haoozhang/spring-cloud-azure-starter-eventhubs-sample

Code Snippet
Add the code snippet that causes the issue.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Setup (please complete the following information):

  • OS: [e.g. iOS]
  • IDE: [e.g. IntelliJ] IDEA
  • Library/Libraries: [e.g. com.azure:azure-core:1.16.0 (groupId:artifactId:version)] spring-cloud-azure-starter-eventhubs 5.18.0
  • Java version: [e.g. 8] 17
  • App Server/Environment: [e.g. Tomcat, WildFly, Azure Function, Apache Spark, Databricks, IDE plugin or anything special]
  • Frameworks: [e.g. Spring Boot, Micronaut, Quarkus, etc]

If you suspect a dependency version mismatch (e.g. you see NoClassDefFoundError, NoSuchMethodError or similar), please check out Troubleshoot dependency version conflict article first. If it doesn't provide solution for the problem, please provide:

  • verbose dependency tree (mvn dependency:tree -Dverbose)
  • exception message, full stack trace, and any available logs

Additional context
Add any other context about the problem here.

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.Event Hubsazure-springAll azure-spring related issuesbugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team

Type

No type

Projects

Status

Todo

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions