azure-sdk-for-java: [BUG] Async Event Hubs Producer cannot create an Event batch to send data
Describe the bug
I’m following the guide here to create an EventHubProducerAsyncClient – which is different than the EventHubProducerCluent used in the documentation. When I try creating an EventDataBatch to send my data, I get the error:

Looking more into the error it seems that EventHubProducerClient is a wrapper on top of EventHubProducerAsyncClient and it uses the library Mono to convert the Mono object returned from EventHubProducerAsycClient.createBatch() to EventDataBatch. But if I try to createBatch() directly from the Async Producer Client I’m unable to cast it into an EventDataBatch.
Exception or Stack Trace
.../test-event-hub-producer/src/main/java/EventHubProducerMain.java:[18,60] incompatible types: reactor.core.publisher.Mono<com.azure.messaging.eventhubs.EventDataBatch> cannot be converted to com.azure.messaging.eventhubs.EventDataBatch
To Reproduce
- Create an
EventHubProducerAsyncClientwith the proper connection string and Event Hubs name. More info here. - Try to create an
EventDataBatchto addEventDataobjects to the batch. Get the error in the screenshot above.
Code Snippet
EventHubProducerAsyncClient eventHubProducer = new EventHubClientBuilder().connectionString(connectionString, eventHubName).buildAsyncProducerClient();
EventDataBatch batch = eventHubProducer.createBatch();
Expected behavior
eventHubProducer.createBatch() should return EventDataBatch type or another compatible type which can be casted into EventDataBatch.
Screenshots

Setup (please complete the following information):
- OS: macOS X
- IDE : IntelliJ
- Version of the Library used: 5.0.2
Additional context
I’m using the following dependency in my pom.xml:
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-messaging-eventhubs</artifactId>
<version>5.0.2</version>
</dependency>
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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (6 by maintainers)
Thanks for providing the details. I will look into this issue and let you know.