Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable blocking operation in batch receive #12822

Merged
merged 3 commits into from
Jul 7, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.stream.Collectors;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Signal;
import reactor.core.scheduler.Schedulers;

/**
* The partition pump manager that keeps track of all the partition pumps started by this {@link EventProcessorClient}.
Expand Down Expand Up @@ -164,37 +165,30 @@ void startPartitionPump(PartitionOwnership claimedOwnership, Checkpoint checkpoi

partitionPumps.put(claimedOwnership.getPartitionId(), eventHubConsumer);
//@formatter:off
Flux<Flux<PartitionEvent>> partitionEventFlux;
if (maxWaitTime != null) {
eventHubConsumer
partitionEventFlux = eventHubConsumer
.receiveFromPartition(claimedOwnership.getPartitionId(), startFromEventPosition, receiveOptions)
.windowTimeout(maxBatchSize, maxWaitTime)
.flatMap(Flux::collectList)
.subscribe(partitionEventBatch -> processEvents(partitionContext, partitionProcessor,
eventHubConsumer, partitionEventBatch),
/* EventHubConsumer receive() returned an error */
ex -> handleError(claimedOwnership, eventHubConsumer, partitionProcessor, ex, partitionContext),
() -> {
partitionProcessor.close(new CloseContext(partitionContext,
CloseReason.EVENT_PROCESSOR_SHUTDOWN));
cleanup(claimedOwnership, eventHubConsumer);
});
.windowTimeout(maxBatchSize, maxWaitTime);
} else {
eventHubConsumer
partitionEventFlux = eventHubConsumer
.receiveFromPartition(claimedOwnership.getPartitionId(), startFromEventPosition, receiveOptions)
.window(maxBatchSize)
.flatMap(Flux::collectList)
.subscribe(partitionEventBatch -> {
processEvents(partitionContext, partitionProcessor,
eventHubConsumer, partitionEventBatch);
},
/* EventHubConsumer receive() returned an error */
ex -> handleError(claimedOwnership, eventHubConsumer, partitionProcessor, ex, partitionContext),
() -> {
partitionProcessor.close(new CloseContext(partitionContext,
CloseReason.EVENT_PROCESSOR_SHUTDOWN));
cleanup(claimedOwnership, eventHubConsumer);
});
.window(maxBatchSize);
}
partitionEventFlux
.flatMap(Flux::collectList)
.publishOn(Schedulers.boundedElastic())
.subscribe(partitionEventBatch -> {
processEvents(partitionContext, partitionProcessor,
eventHubConsumer, partitionEventBatch);
},
/* EventHubConsumer receive() returned an error */
ex -> handleError(claimedOwnership, eventHubConsumer, partitionProcessor, ex, partitionContext),
() -> {
partitionProcessor.close(new CloseContext(partitionContext,
CloseReason.EVENT_PROCESSOR_SHUTDOWN));
cleanup(claimedOwnership, eventHubConsumer);
});
//@formatter:on
} catch (Exception ex) {
if (partitionPumps.containsKey(claimedOwnership.getPartitionId())) {
Expand Down