Source:
public void startPartitionPump(PartitionOwnership claimedOwnership) { if (partitionPumps.containsKey(claimedOwnership.getPartitionId())) { logger.info("Consumer is already running for this partition {}", claimedOwnership.getPartitionId()); return; } PartitionContext partitionContext = new PartitionContext(claimedOwnership.getPartitionId(), claimedOwnership.getEventHubName(), claimedOwnership.getConsumerGroupName(), claimedOwnership.getOwnerId(), claimedOwnership.getETag(), partitionManager); PartitionProcessor partitionProcessor = this.partitionProcessorFactory.get(); partitionProcessor.initialize(partitionContext); EventPosition startFromEventPosition; if (claimedOwnership.getOffset() != null) { startFromEventPosition = EventPosition.fromOffset(claimedOwnership.getOffset()); } else if (claimedOwnership.getSequenceNumber() != null) { startFromEventPosition = EventPosition.fromSequenceNumber(claimedOwnership.getSequenceNumber()); } else { startFromEventPosition = initialEventPosition; } EventHubConsumerOptions eventHubConsumerOptions = new EventHubConsumerOptions().setOwnerLevel(0L); EventHubAsyncConsumer eventHubConsumer = eventHubAsyncClient .createConsumer(claimedOwnership.getConsumerGroupName(), claimedOwnership.getPartitionId(), startFromEventPosition, eventHubConsumerOptions); partitionPumps.put(claimedOwnership.getPartitionId(), eventHubConsumer); eventHubConsumer.receive().subscribe(eventData -> { try { Context processSpanContext = startProcessTracingSpan(eventData); if (processSpanContext.getData("span-context").isPresent()) { eventData.addContext("span-context", processSpanContext); } partitionProcessor.processEvent(partitionContext, eventData).doOnEach(signal -> endProcessTracingSpan(processSpanContext, signal)).subscribe(unused -> { }, ex -> handleProcessingError(claimedOwnership, eventHubConsumer, partitionProcessor, ex, partitionContext)); } catch (Exception ex) { handleProcessingError(claimedOwnership, eventHubConsumer, partitionProcessor, ex, partitionContext); } }, ex -> handleReceiveError(claimedOwnership, eventHubConsumer, partitionProcessor, ex, partitionContext), () -> partitionProcessor.close(partitionContext, CloseReason.EVENT_PROCESSOR_SHUTDOWN)); }

Target:
public void startPartitionPump(PartitionOwnership claimedOwnership) { if (partitionPumps.containsKey(claimedOwnership.getPartitionId())) { logger.info("Consumer is already running for this partition {}", claimedOwnership.getPartitionId()); return; } PartitionContext partitionContext = new PartitionContext(claimedOwnership.getPartitionId(), claimedOwnership.getEventHubName(), claimedOwnership.getConsumerGroupName(), claimedOwnership.getOwnerId(), claimedOwnership.getETag(), partitionManager); PartitionProcessor partitionProcessor = this.partitionProcessorFactory.get(); partitionProcessor.initialize(partitionContext); EventPosition startFromEventPosition; if (claimedOwnership.getOffset() != null) { startFromEventPosition = EventPosition.fromOffset(claimedOwnership.getOffset()); } else if (claimedOwnership.getSequenceNumber() != null) { startFromEventPosition = EventPosition.fromSequenceNumber(claimedOwnership.getSequenceNumber()); } else { startFromEventPosition = initialEventPosition; } EventHubConsumerOptions eventHubConsumerOptions = new EventHubConsumerOptions().setOwnerLevel(0L); EventHubAsyncConsumer eventHubConsumer = eventHubAsyncClient .createConsumer(claimedOwnership.getConsumerGroupName(), claimedOwnership.getPartitionId(), startFromEventPosition, eventHubConsumerOptions); partitionPumps.put(claimedOwnership.getPartitionId(), eventHubConsumer); eventHubConsumer.receive().subscribe(eventData -> { try { Context processSpanContext = startProcessTracingSpan(eventData); if (processSpanContext.getData(SPAN_CONTEXT_KEY).isPresent()) { eventData.addContext(SPAN_CONTEXT_KEY, processSpanContext); } partitionProcessor.processEvent(partitionContext, eventData).doOnEach(signal -> endProcessTracingSpan(processSpanContext, signal)).subscribe(unused -> { }, ex -> handleProcessingError(claimedOwnership, eventHubConsumer, partitionProcessor, ex, partitionContext)); } catch (Exception ex) { handleProcessingError(claimedOwnership, eventHubConsumer, partitionProcessor, ex, partitionContext); } }, ex -> handleReceiveError(claimedOwnership, eventHubConsumer, partitionProcessor, ex, partitionContext), () -> partitionProcessor.close(partitionContext, CloseReason.EVENT_PROCESSOR_SHUTDOWN)); }