Search in sources :

Example 1 with SingletonInstance

use of io.smallrye.reactive.messaging.kafka.base.SingletonInstance in project smallrye-reactive-messaging by smallrye.

the class ReactiveKafkaConsumerTest method testOffsetResetLatest.

@Test
public void testOffsetResetLatest() throws Exception {
    int count = 10;
    sendMessages(0, count);
    String groupId = UUID.randomUUID().toString();
    MapBasedConfig config = createConsumerConfig(groupId).with("topic", topic).with(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
    SingletonInstance<KafkaConsumerRebalanceListener> listeners = new SingletonInstance<>(groupId, getKafkaConsumerRebalanceListenerAwaitingAssignation());
    source = new KafkaSource<>(vertx, groupId, new KafkaConnectorIncomingConfiguration(config), listeners, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), 0);
    AssertSubscriber<IncomingKafkaRecord<Integer, String>> subscriber = source.getStream().invoke(this::onReceive).subscribe().withSubscriber(AssertSubscriber.create(10));
    await().until(() -> {
        Map<TopicPartition, Long> map = source.getConsumer().getPositions().await().indefinitely();
        return map.values().stream().mapToLong(l -> l).sum() == 10;
    });
    subscriber.assertSubscribed().assertHasNotReceivedAnyItem();
    sendMessages(count, count);
    await().untilAsserted(() -> assertThat(subscriber.getItems()).hasSize(count));
    await().until(() -> {
        Map<TopicPartition, Long> map = source.getConsumer().getPositions().await().indefinitely();
        return map.values().stream().mapToLong(l -> l).sum() == 20;
    });
    subscriber.cancel();
    checkConsumedMessages(count, count);
}
Also used : KafkaConsumerRebalanceListener(io.smallrye.reactive.messaging.kafka.KafkaConsumerRebalanceListener) IncomingKafkaRecord(io.smallrye.reactive.messaging.kafka.IncomingKafkaRecord) TopicPartition(org.apache.kafka.common.TopicPartition) SingletonInstance(io.smallrye.reactive.messaging.kafka.base.SingletonInstance) KafkaConnectorIncomingConfiguration(io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)

Example 2 with SingletonInstance

use of io.smallrye.reactive.messaging.kafka.base.SingletonInstance in project smallrye-reactive-messaging by smallrye.

the class ClientTestBase method createSourceSeekToOffset.

public KafkaSource<Integer, String> createSourceSeekToOffset() {
    String groupId = UUID.randomUUID().toString();
    MapBasedConfig config = createConsumerConfig(groupId).put("topic", topic);
    SingletonInstance<KafkaConsumerRebalanceListener> listeners = new SingletonInstance<>(groupId, getKafkaConsumerRebalanceListenerAwaitingAssignationAndSeekToOffset());
    source = new KafkaSource<>(vertx, groupId, new KafkaConnectorIncomingConfiguration(config), listeners, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), 0);
    return source;
}
Also used : KafkaConsumerRebalanceListener(io.smallrye.reactive.messaging.kafka.KafkaConsumerRebalanceListener) SingletonInstance(io.smallrye.reactive.messaging.kafka.base.SingletonInstance) KafkaConnectorIncomingConfiguration(io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)

Example 3 with SingletonInstance

use of io.smallrye.reactive.messaging.kafka.base.SingletonInstance in project smallrye-reactive-messaging by smallrye.

the class ClientTestBase method createSourceSeekToEnd.

public KafkaSource<Integer, String> createSourceSeekToEnd() {
    String groupId = UUID.randomUUID().toString();
    MapBasedConfig config = createConsumerConfig(groupId).put("topic", topic);
    SingletonInstance<KafkaConsumerRebalanceListener> listeners = new SingletonInstance<>(groupId, getKafkaConsumerRebalanceListenerAwaitingAssignationAndSeekToEnd());
    source = new KafkaSource<>(vertx, groupId, new KafkaConnectorIncomingConfiguration(config), listeners, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), 0);
    return source;
}
Also used : KafkaConsumerRebalanceListener(io.smallrye.reactive.messaging.kafka.KafkaConsumerRebalanceListener) SingletonInstance(io.smallrye.reactive.messaging.kafka.base.SingletonInstance) KafkaConnectorIncomingConfiguration(io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)

Example 4 with SingletonInstance

use of io.smallrye.reactive.messaging.kafka.base.SingletonInstance in project smallrye-reactive-messaging by smallrye.

the class ClientTestBase method createSourceSeekToBeginning.

public KafkaSource<Integer, String> createSourceSeekToBeginning() {
    String groupId = UUID.randomUUID().toString();
    MapBasedConfig config = createConsumerConfig(groupId).put("topic", topic);
    SingletonInstance<KafkaConsumerRebalanceListener> listeners = new SingletonInstance<>(groupId, getKafkaConsumerRebalanceListenerAwaitingAssignationAndSeekToBeginning());
    source = new KafkaSource<>(vertx, groupId, new KafkaConnectorIncomingConfiguration(config), listeners, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), 0);
    return source;
}
Also used : KafkaConsumerRebalanceListener(io.smallrye.reactive.messaging.kafka.KafkaConsumerRebalanceListener) SingletonInstance(io.smallrye.reactive.messaging.kafka.base.SingletonInstance) KafkaConnectorIncomingConfiguration(io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)

Aggregations

KafkaConnectorIncomingConfiguration (io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration)4 KafkaConsumerRebalanceListener (io.smallrye.reactive.messaging.kafka.KafkaConsumerRebalanceListener)4 SingletonInstance (io.smallrye.reactive.messaging.kafka.base.SingletonInstance)4 MapBasedConfig (io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)4 IncomingKafkaRecord (io.smallrye.reactive.messaging.kafka.IncomingKafkaRecord)1 TopicPartition (org.apache.kafka.common.TopicPartition)1