Azure Event Hubs Java SDK - Examples
Comprehensive code examples for the Azure Event Hubs SDK for Java.
Table of Contents
- Maven Dependency
- EventHubProducerClient
- EventHubConsumerClient
- EventProcessorClient
- Checkpointing Patterns
- Partition Handling
Maven Dependency
xml
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-messaging-eventhubs</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.18.2</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-messaging-eventhubs-checkpointstore-blob</artifactId>
<version>1.21.0</version>
</dependency>EventHubProducerClient
Basic Producer with Azure Identity
java
import com.azure.messaging.eventhubs.*;
import com.azure.identity.DefaultAzureCredentialBuilder;
import java.util.Arrays;
import java.util.List;
import static java.nio.charset.StandardCharsets.UTF_8;
public class PublishEventsWithAzureIdentity {
public static void main(String[] args) {
List<EventData> telemetryEvents = Arrays.asList(
new EventData("Roast beef".getBytes(UTF_8)),
new EventData("Cheese".getBytes(UTF_8)),
new EventData("Tofu".getBytes(UTF_8)),
new EventData("Turkey".getBytes(UTF_8)));
// Create a producer