Search in sources :

Example 1 with IncomingKafkaRecord

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

the class ReactiveKafkaConsumerTest method testThrottledAcknowledgementWithDefaultValues.

@Test
public void testThrottledAcknowledgementWithDefaultValues() throws Exception {
    String groupId = UUID.randomUUID().toString();
    MapBasedConfig config = createConsumerConfig(groupId).put("topic", topic);
    Multi<IncomingKafkaRecord<Integer, String>> stream = createSource(config, groupId).getStream().invoke(IncomingKafkaRecord::ack);
    sendReceive(stream, 0, 100, 0, 100);
    restartAndCheck(config, groupId, 1);
}
Also used : MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) IncomingKafkaRecord(io.smallrye.reactive.messaging.kafka.IncomingKafkaRecord)

Example 2 with IncomingKafkaRecord

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

the class ReactiveKafkaConsumerTest method testWithMultipleConsumersWithAMultipleConsumeGroup.

@Test
public void testWithMultipleConsumersWithAMultipleConsumeGroup() throws Exception {
    int count = 100;
    CountDownLatch latch = new CountDownLatch(count * partitions);
    List<KafkaSource<Integer, String>> sources = new ArrayList<>();
    for (int i = 0; i < partitions; i++) {
        String groupId = UUID.randomUUID().toString();
        MapBasedConfig config = createConsumerConfig(groupId).with("topic", topic).with(ConsumerConfig.CLIENT_ID_CONFIG, "client-" + i).with(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
        KafkaSource<Integer, String> source = createSource(config, groupId);
        sources.add(source);
        source.getStream().invoke(rec -> {
            onReceive(rec);
            latch.countDown();
        }).subscribe().with(IncomingKafkaRecord::ack);
        await().until(() -> !source.getConsumer().getAssignments().await().indefinitely().isEmpty());
    }
    sendMessages(0, count);
    waitForMessages(latch);
    assertThat(sources).hasSize(4);
    assertThat(sources).allSatisfy(s -> assertThat(s.getConsumer().getAssignments().await().indefinitely()).hasSize(partitions));
    sources.forEach(KafkaSource::closeQuietly);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KafkaSource(io.smallrye.reactive.messaging.kafka.impl.KafkaSource) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) IncomingKafkaRecord(io.smallrye.reactive.messaging.kafka.IncomingKafkaRecord)

Example 3 with IncomingKafkaRecord

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

the class ReactiveKafkaConsumerTest method testAutoCommitAcknowledgement.

@Test
public void testAutoCommitAcknowledgement() throws Exception {
    String groupId = UUID.randomUUID().toString();
    MapBasedConfig config = createConsumerConfig(groupId).with("topic", topic).with(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, true);
    Multi<IncomingKafkaRecord<Integer, String>> stream = createSource(config, groupId).getStream().invoke(IncomingKafkaRecord::ack);
    sendReceive(stream, 0, 100, 0, 100);
    restartAndCheck(config, groupId, 1);
}
Also used : MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) IncomingKafkaRecord(io.smallrye.reactive.messaging.kafka.IncomingKafkaRecord)

Example 4 with IncomingKafkaRecord

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

the class ReactiveKafkaConsumerTest method testMessageProcessingDelay.

/**
 * Tests that delays in message processing dont cause session timeouts.
 * Kafka consumer heartbeat thread should keep the session alive.
 */
@Test
public void testMessageProcessingDelay() throws Exception {
    int count = 3;
    String groupId = UUID.randomUUID().toString();
    MapBasedConfig config = createConsumerConfig(groupId).put("topic", topic);
    KafkaSource<Integer, String> source = createSource(config, groupId);
    AssertSubscriber<IncomingKafkaRecord<Integer, String>> subscriber = source.getStream().select().first(count).subscribe().withSubscriber(AssertSubscriber.create(0));
    sendMessages(0, count);
    for (int i = 0; i < count; i++) {
        subscriber.request(1);
        int l = i + 1;
        await().until(() -> subscriber.getItems().size() == l);
        Thread.sleep(sessionTimeoutMillis + 1000);
    }
    subscriber.awaitCompletion();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) IncomingKafkaRecord(io.smallrye.reactive.messaging.kafka.IncomingKafkaRecord)

Example 5 with IncomingKafkaRecord

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

the class ReactiveKafkaConsumerTest method testAcknowledgementUsingThrottledStrategy.

@Test
public void testAcknowledgementUsingThrottledStrategy() throws Exception {
    String groupId = UUID.randomUUID().toString();
    MapBasedConfig config = createConsumerConfig(groupId).with("topic", topic);
    Multi<IncomingKafkaRecord<Integer, String>> stream = createSource(config, groupId).getStream().invoke(IncomingKafkaRecord::ack);
    sendReceive(stream, 0, 100, 0, 100);
    waitForCommits(source, 100);
    // Close consumer and create another one. First consumer should commit final offset on close.
    // Second consumer should receive only new messages.
    cancelSubscriptions();
    clearReceivedMessages();
    config.with(ConsumerConfig.CLIENT_ID_CONFIG, "second-consumer");
    Multi<IncomingKafkaRecord<Integer, String>> stream2 = createSource(config, groupId).getStream();
    sendReceive(stream2, 100, 100, 100, 100);
}
Also used : MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) IncomingKafkaRecord(io.smallrye.reactive.messaging.kafka.IncomingKafkaRecord)

Aggregations

IncomingKafkaRecord (io.smallrye.reactive.messaging.kafka.IncomingKafkaRecord)19 MapBasedConfig (io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)18 KafkaSource (io.smallrye.reactive.messaging.kafka.impl.KafkaSource)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 TopicPartition (org.apache.kafka.common.TopicPartition)6 KafkaConnectorIncomingConfiguration (io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration)5 ConsumerConfig (org.apache.kafka.clients.consumer.ConsumerConfig)4 Uni (io.smallrye.mutiny.Uni)3 CountKafkaCdiEvents (io.smallrye.reactive.messaging.kafka.CountKafkaCdiEvents)3 KafkaConsumerRebalanceListener (io.smallrye.reactive.messaging.kafka.KafkaConsumerRebalanceListener)3 SingletonInstance (io.smallrye.reactive.messaging.kafka.base.SingletonInstance)3 UnsatisfiedInstance (io.smallrye.reactive.messaging.kafka.base.UnsatisfiedInstance)3 java.util (java.util)3 java.util.concurrent (java.util.concurrent)3 Collectors (java.util.stream.Collectors)3 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Awaitility.await (org.awaitility.Awaitility.await)3 Test (org.junit.jupiter.api.Test)3 Multi (io.smallrye.mutiny.Multi)2