Search in sources :

Example 31 with KafkaMapBasedConfig

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

the class KafkaNackPropagationTest method getDoubleNackConfig.

private KafkaMapBasedConfig getDoubleNackConfig() {
    KafkaMapBasedConfig config = kafkaConfig("mp.messaging.outgoing.kafka");
    config.put("value.serializer", IntegerSerializer.class.getName());
    config.put("topic", "double-topic");
    return config;
}
Also used : IntegerSerializer(org.apache.kafka.common.serialization.IntegerSerializer) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)

Example 32 with KafkaMapBasedConfig

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

the class PerformanceProducerTest method testDefault.

@Test
public void testDefault() {
    String topic = UUID.randomUUID().toString();
    companion.topics().createAndWait(topic, 10);
    ConsumerTask<String, Integer> records = companion.consumeIntegers().fromTopics(topic, COUNT, Duration.ofMinutes(1));
    KafkaMapBasedConfig config = kafkaConfig("mp.messaging.outgoing.kafka").put("topic", topic).put("value.serializer", IntegerSerializer.class.getName());
    GeneratorBean bean = runApplication(config, GeneratorBean.class);
    await().until(this::isReady);
    await().until(this::isAlive);
    long begin = System.currentTimeMillis();
    bean.run();
    await().atMost(Duration.ofMinutes(TIMEOUT_IN_MINUTES)).until(() -> bean.count() == COUNT);
    long end = System.currentTimeMillis();
    // Wait until all the messages are read.
    records.awaitCompletion(Duration.ofMinutes(TIMEOUT_IN_MINUTES));
    long duration = end - begin;
    System.out.println("Time " + duration + " ms");
    double speed = (COUNT * 1.0) / (duration / 1000.0);
    System.out.println(speed + " messages/ms");
}
Also used : IntegerSerializer(org.apache.kafka.common.serialization.IntegerSerializer) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 33 with KafkaMapBasedConfig

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

the class PerformanceProducerTest method testWithoutBackPressureAndIncreaseKafkaRequests.

@Test
public void testWithoutBackPressureAndIncreaseKafkaRequests() {
    String topic = UUID.randomUUID().toString();
    companion.topics().createAndWait(topic, 10);
    ConsumerTask<String, Integer> consumed = companion.consumeIntegers().fromTopics(topic, COUNT, Duration.ofMinutes(TIMEOUT_IN_MINUTES));
    KafkaMapBasedConfig config = kafkaConfig("mp.messaging.outgoing.kafka").put("topic", topic).put("max-inflight-messages", 0L).put("max.in.flight.requests.per.connection", 100).put("value.serializer", IntegerSerializer.class.getName());
    GeneratorBean bean = runApplication(config, GeneratorBean.class);
    await().until(this::isReady);
    await().until(this::isAlive);
    long begin = System.currentTimeMillis();
    bean.run();
    await().atMost(Duration.ofMinutes(TIMEOUT_IN_MINUTES)).until(() -> bean.count() == COUNT);
    long end = System.currentTimeMillis();
    // Wait until all the messages are read.
    consumed.awaitCompletion(Duration.ofMinutes(TIMEOUT_IN_MINUTES));
    long duration = end - begin;
    System.out.println("Time " + duration + " ms");
    double speed = (COUNT * 1.0) / (duration / 1000.0);
    System.out.println(speed + " messages/ms");
}
Also used : IntegerSerializer(org.apache.kafka.common.serialization.IntegerSerializer) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 34 with KafkaMapBasedConfig

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

the class PerformanceProducerTest method testWithoutBackPressureAndIdempotence.

@Test
public void testWithoutBackPressureAndIdempotence() throws InterruptedException {
    String topic = UUID.randomUUID().toString();
    companion.topics().createAndWait(topic, 10);
    ConsumerTask<String, Integer> consumed = companion.consumeIntegers().fromTopics(topic, COUNT, Duration.ofMinutes(TIMEOUT_IN_MINUTES));
    KafkaMapBasedConfig config = kafkaConfig("mp.messaging.outgoing.kafka").put("topic", topic).put("max-inflight-messages", 0L).put("enable.idempotence", true).put("acks", "all").put("value.serializer", IntegerSerializer.class.getName());
    GeneratorBean bean = runApplication(config, GeneratorBean.class);
    await().until(this::isReady);
    await().until(this::isAlive);
    long begin = System.currentTimeMillis();
    bean.run();
    await().atMost(Duration.ofMinutes(TIMEOUT_IN_MINUTES)).until(() -> bean.count() == COUNT);
    long end = System.currentTimeMillis();
    // Wait until all the messages are read.
    consumed.awaitCompletion(Duration.ofMinutes(TIMEOUT_IN_MINUTES));
    long duration = end - begin;
    System.out.println("Time " + duration + " ms");
    double speed = (COUNT * 1.0) / (duration / 1000.0);
    System.out.println(speed + " messages/ms");
}
Also used : IntegerSerializer(org.apache.kafka.common.serialization.IntegerSerializer) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 35 with KafkaMapBasedConfig

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

the class ConsumerRecordConverterTest method testBeanUsingConverter.

@Test
public void testBeanUsingConverter() {
    KafkaMapBasedConfig builder = kafkaConfig("mp.messaging.incoming.data");
    builder.put("value.deserializer", StringDeserializer.class.getName());
    builder.put("auto.offset.reset", "earliest");
    builder.put("topic", topic);
    addBeans(ConsumerRecordConverter.class, RecordConverter.class);
    MyBean bean = runApplication(builder, MyBean.class);
    companion.produceStrings().usingGenerator(i -> new ProducerRecord<>(topic, i % 2 == 0 ? "key" : "k", "v-" + i), 10);
    await().until(() -> bean.list().size() == 10);
    assertThat(bean.list()).hasSize(10).allSatisfy(r -> {
        assertThat(r.value()).startsWith("v-");
        assertThat(r.key()).startsWith("k");
        if (!r.key().equalsIgnoreCase("key")) {
            assertThat(r.key()).isEqualTo("k");
        }
    });
}
Also used : StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) 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