in Sample-Code-Snippets/Java/Spring-Boot/eventhubs-client/src/main/java/com/Azure/Testing/EventHubClient/EventHubClientApplication.java [37:55]
public void run(String... args) throws Exception {
LOGGER.info("Event Hub producer client created");
producerClient.send(Arrays.asList(new EventData("Test event - Hello World")));
LOGGER.info("Sent message to Event Hub");
producerClient.close();
TimeUnit.SECONDS.sleep(2);
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.warn("Failed to receive message.");
}
}