How to read event only once in Azure Event Hub

1.3k Views Asked by At

I want to read events only once from Azure Event hub so that event gets processed only once. But while reading these events getting same event in all partitions.

Tech Stack - Spring boot to read events via

EventProcessorHost host = EventProcessorHost.EventProcessorHostBuilder
            .newBuilder(EventProcessorHost.createHostName(hostNamePrefix), 
consumerGroupName)
            .useAzureStorageCheckpointLeaseManager(storageConnectionString, storageContainerName, null)
            .useEventHubConnectionString(eventHubConnectionString.toString(), eventHubName)
            .build();

Thanks.

1

There are 1 best solutions below

0
On

You can create up to 32 partition on Eventhub but when you send a message that will go only on single partition (if you would not put partition-id, Eventhub will send message to random partition )

Event Hubs retains data for a configured retention time that applies across all partitions in the event hub. Events expire on a time basis; you cannot explicitly delete them. Because partitions are independent and contain their own sequence of data, they often grow at different rates. partitions

maybe issue with your code, To confirm this behaviour you can use Microsoft ServiceBusExplorer to send and receive messages from Eventhub. When you will create Eventhub listener through Service bus you can receive partition-id and messages in real-time.