Search in sources :

Example 81 with KafkaMapBasedConfig

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

the class KafkaSourceTest method myKafkaSourceConfig.

private KafkaMapBasedConfig myKafkaSourceConfig(String topic, String group) {
    KafkaMapBasedConfig config = kafkaConfig("mp.messaging.incoming.data");
    config.put("group.id", group);
    config.put("value.deserializer", IntegerDeserializer.class.getName());
    config.put("enable.auto.commit", "false");
    config.put("auto.offset.reset", "earliest");
    config.put("topic", topic);
    return config;
}
Also used : IntegerDeserializer(org.apache.kafka.common.serialization.IntegerDeserializer) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)

Example 82 with KafkaMapBasedConfig

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

the class KafkaSourceTest method myKafkaSourceConfigWithoutAck.

private KafkaMapBasedConfig myKafkaSourceConfigWithoutAck(String suffix, boolean shorterTimeouts) {
    KafkaMapBasedConfig config = kafkaConfig("mp.messaging.incoming.data");
    config.put("group.id", "my-group-starting-on-fifth-" + suffix);
    config.put("value.deserializer", IntegerDeserializer.class.getName());
    config.put("enable.auto.commit", "false");
    config.put("auto.offset.reset", "earliest");
    config.put("topic", "data-starting-on-fifth-" + suffix);
    if (shorterTimeouts) {
        config.put("max.poll.interval.ms", "2000");
    }
    return config;
}
Also used : IntegerDeserializer(org.apache.kafka.common.serialization.IntegerDeserializer) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)

Example 83 with KafkaMapBasedConfig

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

the class KafkaSourceTest method myKafkaSourceConfig.

// @SuppressWarnings({ "rawtypes" })
// @Test
// public void testRecoveryAfterMissedHeartbeat() throws InterruptedException {
// MapBasedConfig config = newCommonConfigForSource()
// .with("bootstrap.servers", KafkaBrokerExtension.usage.getBootstrapServers())
// .with("value.deserializer", IntegerDeserializer.class.getName())
// .with(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, 6000)
// .with(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG, 100)
// .with("retry", true)
// .with("retry-attempts", 100)
// .with("retry-max-wait", 30);
// 
// usage.setBootstrapServers(KafkaBrokerExtension.usage.getBootstrapServers());
// 
// KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
// source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic,
// UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents,
// UnsatisfiedInstance.instance(), -1);
// List<KafkaRecord> messages1 = new ArrayList<>();
// source.getStream().subscribe().with(messages1::add);
// 
// AtomicInteger counter = new AtomicInteger();
// usage.produceIntegers(10, null,
// () -> new ProducerRecord<>(topic, counter.getAndIncrement()))).start();
// 
// await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 10);
// 
// KafkaBrokerExtension.getProxy().setConnectionCut(true);
// Thread.sleep(6000 + 500); // session timeout + a bit more just in case.
// KafkaBrokerExtension.getProxy().setConnectionCut(false);
// 
// usage.produceIntegers(10, null,
// () -> new ProducerRecord<>(topic, counter.getAndIncrement()))).start();
// 
// await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 20);
// assertThat(messages1.size()).isGreaterThanOrEqualTo(20);
// }
private KafkaMapBasedConfig myKafkaSourceConfig(String topic, int partitions, String withConsumerRebalanceListener, String group) {
    KafkaMapBasedConfig config = kafkaConfig("mp.messaging.incoming.data");
    if (group != null) {
        config.put("group.id", group);
    }
    config.put("value.deserializer", IntegerDeserializer.class.getName());
    config.put("enable.auto.commit", "false");
    config.put("auto.offset.reset", "earliest");
    config.put("topic", topic);
    if (partitions > 0) {
        config.put("partitions", Integer.toString(partitions));
    }
    if (withConsumerRebalanceListener != null) {
        config.put("consumer-rebalance-listener.name", withConsumerRebalanceListener);
    }
    return config;
}
Also used : IntegerDeserializer(org.apache.kafka.common.serialization.IntegerDeserializer) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)

Example 84 with KafkaMapBasedConfig

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

the class KafkaSinkTest method getKafkaSinkConfigWithMultipleUpstreams.

private KafkaMapBasedConfig getKafkaSinkConfigWithMultipleUpstreams(String t) {
    KafkaMapBasedConfig config = kafkaConfig("mp.messaging.outgoing.data");
    config.put("key.serializer", StringSerializer.class.getName());
    config.put("value.serializer", IntegerSerializer.class.getName());
    config.put("merge", true);
    if (t != null) {
        config.put("topic", t);
    }
    return config;
}
Also used : StringSerializer(org.apache.kafka.common.serialization.StringSerializer) IntegerSerializer(org.apache.kafka.common.serialization.IntegerSerializer) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)

Example 85 with KafkaMapBasedConfig

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

the class KafkaSinkTest method getKafkaSinkConfigForRecordProducingBean.

private KafkaMapBasedConfig getKafkaSinkConfigForRecordProducingBean(String t) {
    KafkaMapBasedConfig config = kafkaConfig("mp.messaging.outgoing.output-record");
    config.put("key.serializer", IntegerSerializer.class.getName());
    config.put("value.serializer", StringSerializer.class.getName());
    if (t != null) {
        config.put("topic", t);
    }
    return config;
}
Also used : IntegerSerializer(org.apache.kafka.common.serialization.IntegerSerializer) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)

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