Search in sources :

Example 21 with KafkaMapBasedConfig

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

the class KafkaSinkWithCloudEventsTest method testSendingStructuredCloudEventsWithWrongSerializer.

@Test
public void testSendingStructuredCloudEventsWithWrongSerializer() {
    KafkaMapBasedConfig config = newCommonConfig();
    config.put("topic", topic);
    config.put("value.serializer", DoubleSerializer.class.getName());
    config.put("channel-name", topic);
    config.put("cloud-events-mode", "structured");
    KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
    assertThatThrownBy(() -> new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance())).isInstanceOf(IllegalStateException.class);
}
Also used : DoubleSerializer(org.apache.kafka.common.serialization.DoubleSerializer) KafkaSink(io.smallrye.reactive.messaging.kafka.impl.KafkaSink) KafkaConnectorOutgoingConfiguration(io.smallrye.reactive.messaging.kafka.KafkaConnectorOutgoingConfiguration) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 22 with KafkaMapBasedConfig

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

the class BatchConsumerTest method testIncomingConsumingMessageWithMetadata.

@Test
void testIncomingConsumingMessageWithMetadata() {
    String newTopic = UUID.randomUUID().toString();
    companion.topics().createAndWait(newTopic, 3);
    KafkaMapBasedConfig config = kafkaConfig("mp.messaging.incoming.kafka").put("value.deserializer", StringDeserializer.class.getName()).put("auto.offset.reset", "earliest").put("topic", newTopic).put("batch", true);
    BeanConsumingMessageWithBatchMetadata bean = runApplication(config, BeanConsumingMessageWithBatchMetadata.class);
    companion.produceStrings().usingGenerator(i -> new ProducerRecord<>(newTopic, "k-" + i, "v-" + i), 10);
    await().until(() -> bean.metadata().stream().mapToInt(m -> m.getRecords().count()).sum() == 10);
    Map<TopicPartition, List<ConsumerRecord<String, String>>> records = new HashMap<>();
    for (IncomingKafkaRecordBatchMetadata<String, String> metadata : bean.metadata()) {
        for (TopicPartition partition : metadata.getRecords().partitions()) {
            List<ConsumerRecord<String, String>> list = records.computeIfAbsent(partition, p -> new ArrayList<>());
            list.addAll(metadata.getRecords().records(partition));
        }
    }
    assertThat(records.keySet()).hasSize(3);
    assertThat(records.values()).flatMap(l -> l).hasSize(10).allSatisfy(r -> {
        assertThat(r.value()).startsWith("v-");
        assertThat(r.key()).startsWith("k");
    });
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) Awaitility.await(org.awaitility.Awaitility.await) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) KafkaCompanionTestBase(io.smallrye.reactive.messaging.kafka.base.KafkaCompanionTestBase) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) UUID(java.util.UUID) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) Message(org.eclipse.microprofile.reactive.messaging.Message) CompletionStage(java.util.concurrent.CompletionStage) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Map(java.util.Map) ApplicationScoped(javax.enterprise.context.ApplicationScoped) IncomingKafkaRecordBatchMetadata(io.smallrye.reactive.messaging.kafka.api.IncomingKafkaRecordBatchMetadata) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Incoming(org.eclipse.microprofile.reactive.messaging.Incoming) HashMap(java.util.HashMap) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) TopicPartition(org.apache.kafka.common.TopicPartition) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 23 with KafkaMapBasedConfig

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

the class BatchConsumerTest method testIncomingConsumingKafkaBatchRecords.

@Test
void testIncomingConsumingKafkaBatchRecords() {
    KafkaMapBasedConfig config = kafkaConfig("mp.messaging.incoming.kafka").put("value.deserializer", StringDeserializer.class.getName()).put("auto.offset.reset", "earliest").put("topic", topic).put("batch", true);
    BeanConsumingKafkaRecordBatch bean = runApplication(config, BeanConsumingKafkaRecordBatch.class);
    companion.produceStrings().usingGenerator(i -> new ProducerRecord<>(topic, "k-" + i, "v-" + i), 10);
    await().until(() -> bean.messages().size() == 10);
    assertThat(bean.messages()).hasSize(10).allSatisfy(r -> {
        assertThat(r.getKey()).startsWith("k-");
        assertThat(r.getPayload()).startsWith("v-");
    });
}
Also used : KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 24 with KafkaMapBasedConfig

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

the class RetryTest method getConfig.

private KafkaMapBasedConfig getConfig(String topic) {
    KafkaMapBasedConfig config = kafkaConfig("mp.messaging.incoming.kafka");
    config.put("group.id", UUID.randomUUID().toString());
    config.put("topic", topic);
    config.put("value.deserializer", StringDeserializer.class.getName());
    config.put("enable.auto.commit", "false");
    config.put("auto.offset.reset", "earliest");
    config.put("failure-strategy", "ignore");
    return config;
}
Also used : StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)

Example 25 with KafkaMapBasedConfig

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

the class HealthCheckTest method testHealthOfApplicationWithChannel.

@Test
public void testHealthOfApplicationWithChannel() {
    KafkaMapBasedConfig config = getKafkaSourceConfig(topic);
    LazyConsumingBean bean = runApplication(config, LazyConsumingBean.class);
    ProducerTask produced = companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, "key", i), 10);
    await().until(this::isStarted);
    await().until(this::isReady);
    await().until(this::isAlive);
    produced.awaitCompletion(Duration.ofMinutes(1));
    Multi<Integer> channel = bean.getChannel();
    channel.select().first(10).collect().asList().await().atMost(Duration.ofSeconds(10));
    HealthReport startup = getHealth().getStartup();
    HealthReport liveness = getHealth().getLiveness();
    HealthReport readiness = getHealth().getReadiness();
    assertThat(startup.isOk()).isTrue();
    assertThat(liveness.isOk()).isTrue();
    assertThat(readiness.isOk()).isTrue();
    assertThat(startup.getChannels()).hasSize(1);
    assertThat(liveness.getChannels()).hasSize(1);
    assertThat(readiness.getChannels()).hasSize(1);
}
Also used : HealthReport(io.smallrye.reactive.messaging.health.HealthReport) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) ProducerTask(io.smallrye.reactive.messaging.kafka.companion.ProducerTask) Test(org.junit.jupiter.api.Test)

Aggregations

KafkaMapBasedConfig (io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)86 Test (org.junit.jupiter.api.Test)56 Message (org.eclipse.microprofile.reactive.messaging.Message)34 RecordHeader (org.apache.kafka.common.header.internals.RecordHeader)30 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)25 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)22 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)20 JsonObject (io.vertx.core.json.JsonObject)19 ArrayList (java.util.ArrayList)18 KafkaConnectorIncomingConfiguration (io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration)17 KafkaConnectorOutgoingConfiguration (io.smallrye.reactive.messaging.kafka.KafkaConnectorOutgoingConfiguration)17 KafkaSink (io.smallrye.reactive.messaging.kafka.impl.KafkaSink)17 IncomingKafkaCloudEventMetadata (io.smallrye.reactive.messaging.kafka.IncomingKafkaCloudEventMetadata)14 IntegerDeserializer (org.apache.kafka.common.serialization.IntegerDeserializer)14 IntegerSerializer (org.apache.kafka.common.serialization.IntegerSerializer)13 JsonObjectDeserializer (io.vertx.kafka.client.serialization.JsonObjectDeserializer)5 Header (org.apache.kafka.common.header.Header)5 HealthReport (io.smallrye.reactive.messaging.health.HealthReport)4 KafkaCompanionTestBase (io.smallrye.reactive.messaging.kafka.base.KafkaCompanionTestBase)3 List (java.util.List)3