EventPosition checkpointToOffset(Checkpoint startingCheckpoint) { EventPosition startAt = null; if (startingCheckpoint == null) { // No checkpoint was ever stored. Use the initialOffsetProvider instead. Function<String, EventPosition> initialPositionProvider = this.hostContext.getEventProcessorOptions().getInitialPositionProvider(); TRACE_LOGGER.debug(this.hostContext.withHostAndPartition(this.partitionId, "Calling user-provided initial position provider")); startAt = initialPositionProvider.apply(this.partitionId); // Leave this.offset as null. The initialPositionProvider cannot provide enough information to write a valid checkpoint: // at most if will give one of offset or sequence number, and if it is a starting time then it doesn't have either. TRACE_LOGGER.info(this.hostContext.withHostAndPartition(this.partitionId, "Initial position provided: " + startAt)); } else { // Checkpoint is valid, use it. this.offset = startingCheckpoint.getOffset(); startAt = EventPosition.fromOffset(this.offset); this.sequenceNumber = startingCheckpoint.getSequenceNumber(); TRACE_LOGGER.info(this.hostContext.withHostAndPartition(this.partitionId, "Retrieved starting offset " + this.offset + "//" + this.sequenceNumber)); } return startAt; }
private void renewPartitionReceiver(SystemStreamPartition ssp) { String streamId = config.getStreamId(ssp.getStream()); EventHubClientManager eventHubClientManager = perPartitionEventHubManagers.get(ssp); String offset = streamPartitionOffsets.get(ssp); Integer partitionId = ssp.getPartition().getPartitionId(); String consumerGroup = config.getStreamConsumerGroup(ssp.getSystem(), streamId); try { // Close current receiver streamPartitionReceivers.get(ssp).close().get(DEFAULT_SHUTDOWN_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); // Recreate receiver PartitionReceiver receiver = eventHubClientManager.getEventHubClient() .createReceiverSync(consumerGroup, partitionId.toString(), EventPosition.fromOffset(offset, !offset.equals(EventHubSystemConsumer.START_OF_STREAM))); receiver.setPrefetchCount(prefetchCount); // Timeout for EventHubClient receive receiver.setReceiveTimeout(DEFAULT_EVENTHUB_RECEIVER_TIMEOUT); // Create and start receiver thread with handler receiver.setReceiveHandler(streamPartitionHandlers.get(ssp)); streamPartitionReceivers.put(ssp, receiver); } catch (Exception e) { eventHubNonTransientError.set(new SamzaException( String.format("Failed to recreate receiver for EventHubs after ReceiverHandlerError (ssp=%s)", ssp), e)); } }
EventPosition.fromOffset(offset, /* inclusiveFlag */false));
consumer.start(); Assert.assertEquals(EventPosition.fromOffset(EventHubSystemConsumer.START_OF_STREAM, false).toString(), eventHubClientWrapperFactory.getPartitionOffset(String.valueOf(partitionId)).toString());