Search in sources :

Example 11 with KafkaConnectorIncomingConfiguration

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

the class ReactiveKafkaConsumerTest method testRebalanceWhilePausedAndPendingCommit.

@Test
public void testRebalanceWhilePausedAndPendingCommit() throws Exception {
    String groupId = UUID.randomUUID().toString();
    MapBasedConfig config = createConsumerConfig(groupId).put("topic", topic);
    MapBasedConfig config2 = createConsumerConfig(groupId).with(ConsumerConfig.CLIENT_ID_CONFIG, "consumer-" + groupId + "-2").with("topic", topic);
    List<IncomingKafkaRecord<Integer, String>> list = new CopyOnWriteArrayList<>();
    List<IncomingKafkaRecord<Integer, String>> list2 = new CopyOnWriteArrayList<>();
    // The first source do not commit for now.
    Multi<IncomingKafkaRecord<Integer, String>> stream = createSource(config, groupId).getStream().invoke(list::add);
    AssertSubscriber<IncomingKafkaRecord<Integer, String>> subscriber = stream.subscribe().withSubscriber(AssertSubscriber.create(0));
    waitForPartitionAssignment();
    sendMessages(0, 100);
    // Request 50 messages and wait for them to be received. They are not acknowledged
    subscriber.request(50);
    await().until(() -> list.size() == 50);
    // Create the second source acknowledging the message.
    // The rebalance will split the partitions between the 2 sources, but both will restaert from offset 0, as nothing
    // has been acked.
    KafkaSource<Integer, String> source2 = new KafkaSource<>(vertx, groupId, new KafkaConnectorIncomingConfiguration(config2), UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), 3);
    source2.getStream().invoke(i -> {
        list2.add(i);
        i.ack();
    }).subscribe().withSubscriber(AssertSubscriber.create(100));
    await().until(() -> !source2.getConsumer().getAssignments().await().indefinitely().isEmpty());
    // Verify rebalance
    await().until(() -> Uni.combine().all().unis(source.getConsumer().getAssignments(), source2.getConsumer().getAssignments()).combinedWith((tp1, tp2) -> tp1.size() + tp2.size()).await().indefinitely() == partitions);
    Set<TopicPartition> assignedToSource2 = source2.getConsumer().getAssignments().await().indefinitely();
    subscriber.request(100);
    await().until(() -> list.size() >= 100);
    await().until(() -> list2.size() == assignedToSource2.size() * 25);
    // Acknowledge messages, even these received before the rebalance.
    list.forEach(IncomingKafkaRecord::ack);
    // Verify that the 100 messages have been received.
    await().untilAsserted(() -> {
        List<String> receivedByFirstSource = list.stream().map(i -> i.getPartition() + "/" + i.getOffset()).collect(Collectors.toList());
        List<String> receivedBySecondSource = list2.stream().map(i -> i.getPartition() + "/" + i.getOffset()).collect(Collectors.toList());
        Set<String> set = new HashSet<>(receivedByFirstSource);
        set.addAll(receivedBySecondSource);
        assertThat(set).hasSize(100);
    });
    source2.closeQuietly();
}
Also used : AssertSubscriber(io.smallrye.mutiny.helpers.test.AssertSubscriber) java.util(java.util) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) AUTO_COMMIT_INTERVAL_MS_CONFIG(org.apache.kafka.clients.consumer.ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Multi(io.smallrye.mutiny.Multi) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Uni(io.smallrye.mutiny.Uni) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingletonInstance(io.smallrye.reactive.messaging.kafka.base.SingletonInstance) Duration(java.time.Duration) CountKafkaCdiEvents(io.smallrye.reactive.messaging.kafka.CountKafkaCdiEvents) METADATA_MAX_AGE_CONFIG(org.apache.kafka.clients.consumer.ConsumerConfig.METADATA_MAX_AGE_CONFIG) TopicPartition(org.apache.kafka.common.TopicPartition) Infrastructure(io.smallrye.mutiny.infrastructure.Infrastructure) Awaitility.await(org.awaitility.Awaitility.await) TestTags(io.smallrye.reactive.messaging.kafka.TestTags) java.util.concurrent(java.util.concurrent) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) UnsatisfiedInstance(io.smallrye.reactive.messaging.kafka.base.UnsatisfiedInstance) Collectors(java.util.stream.Collectors) KafkaConsumerRebalanceListener(io.smallrye.reactive.messaging.kafka.KafkaConsumerRebalanceListener) org.junit.jupiter.api(org.junit.jupiter.api) KafkaConnectorIncomingConfiguration(io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration) KafkaSource(io.smallrye.reactive.messaging.kafka.impl.KafkaSource) IncomingKafkaRecord(io.smallrye.reactive.messaging.kafka.IncomingKafkaRecord) KafkaSource(io.smallrye.reactive.messaging.kafka.impl.KafkaSource) IncomingKafkaRecord(io.smallrye.reactive.messaging.kafka.IncomingKafkaRecord) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TopicPartition(org.apache.kafka.common.TopicPartition) KafkaConnectorIncomingConfiguration(io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)

Example 12 with KafkaConnectorIncomingConfiguration

use of io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration 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 13 with KafkaConnectorIncomingConfiguration

use of io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration 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 14 with KafkaConnectorIncomingConfiguration

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

the class KafkaClientReactiveStreamsPublisherTest method createSource.

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

Example 15 with KafkaConnectorIncomingConfiguration

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

the class DeprecatedCommitStrategiesTest method testFailureWhenNoRebalanceListenerMatchGivenName.

@Test
public void testFailureWhenNoRebalanceListenerMatchGivenName() {
    MapBasedConfig config = commonConfiguration();
    config.with("client.id", UUID.randomUUID().toString()).with("consumer-rebalance-listener.name", "my-missing-name");
    String group = UUID.randomUUID().toString();
    assertThatThrownBy(() -> {
        new KafkaSource<>(vertx, group, new KafkaConnectorIncomingConfiguration(config), getConsumerRebalanceListeners(), CountKafkaCdiEvents.noCdiEvents, getDeserializationFailureHandlers(), -1);
    }).isInstanceOf(UnsatisfiedResolutionException.class);
}
Also used : KafkaConnectorIncomingConfiguration(io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Test(org.junit.jupiter.api.Test)

Aggregations

KafkaConnectorIncomingConfiguration (io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration)37 Test (org.junit.jupiter.api.Test)31 Message (org.eclipse.microprofile.reactive.messaging.Message)28 ArrayList (java.util.ArrayList)27 MapBasedConfig (io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)20 KafkaMapBasedConfig (io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)18 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)17 RecordHeader (org.apache.kafka.common.header.internals.RecordHeader)17 IncomingKafkaCloudEventMetadata (io.smallrye.reactive.messaging.kafka.IncomingKafkaCloudEventMetadata)14 TopicPartition (org.apache.kafka.common.TopicPartition)13 JsonObject (io.vertx.core.json.JsonObject)12 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)10 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)9 KafkaSource (io.smallrye.reactive.messaging.kafka.impl.KafkaSource)8 HealthReport (io.smallrye.reactive.messaging.health.HealthReport)7 CountKafkaCdiEvents (io.smallrye.reactive.messaging.kafka.CountKafkaCdiEvents)6 IncomingKafkaRecord (io.smallrye.reactive.messaging.kafka.IncomingKafkaRecord)6 Collectors (java.util.stream.Collectors)6 IntegerDeserializer (org.apache.kafka.common.serialization.IntegerDeserializer)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6