use of com.rabbitmq.stream.impl.OffsetTrackingCoordinator.Registration in project rabbitmq-stream-java-client by rabbitmq.
the class StreamEnvironment method registerTrackingConsumer.
TrackingConsumerRegistration registerTrackingConsumer(StreamConsumer streamConsumer, TrackingConfiguration configuration) {
Runnable closingCallable = this.producersCoordinator.registerTrackingConsumer(streamConsumer);
Registration offsetTrackingRegistration;
if (this.offsetTrackingCoordinator.needTrackingRegistration(configuration)) {
offsetTrackingRegistration = this.offsetTrackingCoordinator.registerTrackingConsumer(streamConsumer, configuration);
} else {
offsetTrackingRegistration = null;
}
Runnable closingSequence;
if (offsetTrackingRegistration == null) {
closingSequence = closingCallable;
} else {
closingSequence = () -> {
try {
LOGGER.debug("Executing offset tracking registration closing sequence");
offsetTrackingRegistration.closingCallback().run();
LOGGER.debug("Offset tracking registration closing sequence executed");
} catch (Exception e) {
LOGGER.warn("Error while executing offset tracking registration closing sequence: {}", e.getMessage());
}
closingCallable.run();
};
}
return new TrackingConsumerRegistration(closingSequence, offsetTrackingRegistration == null ? null : offsetTrackingRegistration.postMessageProcessingCallback(), offsetTrackingRegistration == null ? Utils.NO_OP_LONG_CONSUMER : offsetTrackingRegistration.trackingCallback());
}
use of com.rabbitmq.stream.impl.OffsetTrackingCoordinator.Registration in project rabbitmq-stream-java-client by rabbitmq.
the class OffsetTrackingCoordinatorTest method autoShouldNotStoreLastProcessedOffsetOnClosingIfBehindStoredOffset.
@Test
void autoShouldNotStoreLastProcessedOffsetOnClosingIfBehindStoredOffset() {
Duration checkInterval = Duration.ofMillis(100);
OffsetTrackingCoordinator coordinator = new OffsetTrackingCoordinator(env, checkInterval);
when(consumer.lastStoredOffset()).thenReturn(15L);
Registration registration = coordinator.registerTrackingConsumer(consumer, new TrackingConfiguration(true, true, 1, Duration.ofHours(1), Duration.ZERO));
long lastProcessedOffset = 10;
registration.postMessageProcessingCallback().accept(context(lastProcessedOffset, () -> {
}));
registration.closingCallback().run();
verify(consumer, never()).store(anyLong());
}
use of com.rabbitmq.stream.impl.OffsetTrackingCoordinator.Registration in project rabbitmq-stream-java-client by rabbitmq.
the class OffsetTrackingCoordinatorTest method autoShouldStoreLastProcessedOffsetOnClosing.
@Test
void autoShouldStoreLastProcessedOffsetOnClosing() {
Duration checkInterval = Duration.ofMillis(100);
OffsetTrackingCoordinator coordinator = new OffsetTrackingCoordinator(env, checkInterval);
when(consumer.lastStoredOffset()).thenReturn(5L);
Registration registration = coordinator.registerTrackingConsumer(consumer, new TrackingConfiguration(true, true, 1, Duration.ofHours(1), Duration.ZERO));
long lastProcessedOffset = 10;
registration.postMessageProcessingCallback().accept(context(lastProcessedOffset, () -> {
}));
registration.closingCallback().run();
verify(consumer, times(1)).store(lastProcessedOffset);
}
Aggregations