Search in sources :

Example 1 with BlobCheckpointStore

use of com.azure.messaging.eventhubs.checkpointstore.blob.BlobCheckpointStore in project springboot-samples by joergjo.

the class EventHubWorker method run.

public void run() {
    logger.info("Worker is starting");
    var blobContainerAsyncClient = new BlobContainerClientBuilder().connectionString(storageConnectionString).containerName(containerName).buildAsyncClient();
    Consumer<EventContext> processEvent = eventContext -> {
        logger.info("Processing event: Event Hub name = {}; consumer group name = {}; partition id = {}; sequence number = {}", eventContext.getPartitionContext().getEventHubName(), eventContext.getPartitionContext().getConsumerGroup(), eventContext.getPartitionContext().getPartitionId(), eventContext.getEventData().getSequenceNumber());
        eventContext.updateCheckpoint();
        total.increment();
    };
    Consumer<ErrorContext> processError = errorContext -> {
        logger.error("Error while processing {}, {}, {}, {}", errorContext.getPartitionContext().getEventHubName(), errorContext.getPartitionContext().getConsumerGroup(), errorContext.getPartitionContext().getPartitionId(), errorContext.getThrowable().getMessage());
    };
    eventProcessorClient = new EventProcessorClientBuilder().consumerGroup(consumerGroup).connectionString(eventHubConnectionString, eventHubName).processEvent(processEvent).processError(processError).checkpointStore(new BlobCheckpointStore(blobContainerAsyncClient)).buildEventProcessorClient();
    eventProcessorClient.start();
    logger.info("Worker has started");
}
Also used : EventContext(com.azure.messaging.eventhubs.models.EventContext) Counter(io.micrometer.core.instrument.Counter) Logger(org.slf4j.Logger) EventContext(com.azure.messaging.eventhubs.models.EventContext) LoggerFactory(org.slf4j.LoggerFactory) EventProcessorClient(com.azure.messaging.eventhubs.EventProcessorClient) BlobCheckpointStore(com.azure.messaging.eventhubs.checkpointstore.blob.BlobCheckpointStore) ErrorContext(com.azure.messaging.eventhubs.models.ErrorContext) Metrics(io.micrometer.core.instrument.Metrics) Consumer(java.util.function.Consumer) Value(org.springframework.beans.factory.annotation.Value) Component(org.springframework.stereotype.Component) DisposableBean(org.springframework.beans.factory.DisposableBean) EventProcessorClientBuilder(com.azure.messaging.eventhubs.EventProcessorClientBuilder) BlobContainerClientBuilder(com.azure.storage.blob.BlobContainerClientBuilder) EventProcessorClientBuilder(com.azure.messaging.eventhubs.EventProcessorClientBuilder) BlobCheckpointStore(com.azure.messaging.eventhubs.checkpointstore.blob.BlobCheckpointStore) ErrorContext(com.azure.messaging.eventhubs.models.ErrorContext) BlobContainerClientBuilder(com.azure.storage.blob.BlobContainerClientBuilder)

Aggregations

EventProcessorClient (com.azure.messaging.eventhubs.EventProcessorClient)1 EventProcessorClientBuilder (com.azure.messaging.eventhubs.EventProcessorClientBuilder)1 BlobCheckpointStore (com.azure.messaging.eventhubs.checkpointstore.blob.BlobCheckpointStore)1 ErrorContext (com.azure.messaging.eventhubs.models.ErrorContext)1 EventContext (com.azure.messaging.eventhubs.models.EventContext)1 BlobContainerClientBuilder (com.azure.storage.blob.BlobContainerClientBuilder)1 Counter (io.micrometer.core.instrument.Counter)1 Metrics (io.micrometer.core.instrument.Metrics)1 Consumer (java.util.function.Consumer)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 DisposableBean (org.springframework.beans.factory.DisposableBean)1 Value (org.springframework.beans.factory.annotation.Value)1 Component (org.springframework.stereotype.Component)1