Search in sources :

Example 31 with KafkaSink

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

the class KafkaSinkWithLegacyMetadataTest method testSinkUsingInteger.

@SuppressWarnings("unchecked")
@Test
public void testSinkUsingInteger() {
    ConsumerTask<String, Integer> consumed = companion.consumeIntegers().fromTopics(topic, 10, Duration.ofSeconds(10));
    MapBasedConfig config = getBaseConfig().with("topic", topic).with("value.serializer", IntegerSerializer.class.getName()).with("partition", 0).with("channel-name", "testSinkUsingInteger");
    KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
    sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());
    Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
    Multi.createFrom().range(0, 10).map(Message::of).subscribe((Subscriber<? super Message<Integer>>) subscriber);
    assertThat(consumed.awaitCompletion(Duration.ofMinutes(1)).count()).isEqualTo(10);
}
Also used : KafkaSink(io.smallrye.reactive.messaging.kafka.impl.KafkaSink) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) IntegerSerializer(org.apache.kafka.common.serialization.IntegerSerializer) Test(org.junit.jupiter.api.Test)

Example 32 with KafkaSink

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

the class KafkaSinkWithLegacyMetadataTest method testSinkUsingIntegerAndChannelName.

@Test
@SuppressWarnings("unchecked")
public void testSinkUsingIntegerAndChannelName() {
    ConsumerTask<String, Integer> consumed = companion.consumeIntegers().fromTopics(topic, 10, Duration.ofSeconds(10));
    MapBasedConfig config = getBaseConfig().with("channel-name", topic).with("value.serializer", IntegerSerializer.class.getName()).with("partition", 0);
    KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
    sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());
    Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
    Multi.createFrom().range(0, 10).map(Message::of).subscribe((Subscriber<? super Message<Integer>>) subscriber);
    assertThat(consumed.awaitCompletion(Duration.ofMinutes(1)).count()).isEqualTo(10);
}
Also used : KafkaSink(io.smallrye.reactive.messaging.kafka.impl.KafkaSink) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 33 with KafkaSink

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

the class KafkaSinkWithLegacyMetadataTest method testSinkUsingString.

@Test
@SuppressWarnings("unchecked")
public void testSinkUsingString() {
    ConsumerTask<String, String> consumed = companion.consumeStrings().fromTopics(topic, 10, Duration.ofSeconds(10));
    MapBasedConfig config = getBaseConfig().with("topic", topic).with("value.serializer", StringSerializer.class.getName()).with("partition", 0).with("channel-name", "testSinkUsingString");
    KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
    sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());
    Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
    Multi.createFrom().range(0, 10).map(i -> Integer.toString(i)).map(Message::of).subscribe((Subscriber<? super Message<String>>) subscriber);
    assertThat(consumed.awaitCompletion(Duration.ofMinutes(1)).count()).isEqualTo(10);
}
Also used : KafkaSink(io.smallrye.reactive.messaging.kafka.impl.KafkaSink) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) Test(org.junit.jupiter.api.Test)

Example 34 with KafkaSink

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

the class KafkaSinkTest method testSinkUsingString.

@Test
@SuppressWarnings("unchecked")
public void testSinkUsingString() {
    ConsumerTask<String, String> consumed = companion.consumeStrings().fromTopics(topic, 10, Duration.ofSeconds(10));
    MapBasedConfig config = getBaseConfig().with("topic", topic).with("value.serializer", StringSerializer.class.getName()).with("partition", 0).with("channel-name", "testSinkUsingString");
    KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
    sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());
    Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
    Multi.createFrom().range(0, 10).map(i -> Integer.toString(i)).map(Message::of).subscribe((Subscriber<? super Message<String>>) subscriber);
    assertThat(consumed.awaitCompletion(Duration.ofMinutes(1)).count()).isEqualTo(10);
}
Also used : KafkaSink(io.smallrye.reactive.messaging.kafka.impl.KafkaSink) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) Test(org.junit.jupiter.api.Test)

Aggregations

KafkaSink (io.smallrye.reactive.messaging.kafka.impl.KafkaSink)34 Test (org.junit.jupiter.api.Test)32 KafkaMapBasedConfig (io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)27 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)20 KafkaConnectorOutgoingConfiguration (io.smallrye.reactive.messaging.kafka.KafkaConnectorOutgoingConfiguration)18 Message (org.eclipse.microprofile.reactive.messaging.Message)18 MapBasedConfig (io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)16 RecordHeader (org.apache.kafka.common.header.internals.RecordHeader)13 JsonObject (io.vertx.core.json.JsonObject)9 HealthReport (io.smallrye.reactive.messaging.health.HealthReport)4 IntegerSerializer (org.apache.kafka.common.serialization.IntegerSerializer)4 Subscriber (org.reactivestreams.Subscriber)4 Multi (io.smallrye.mutiny.Multi)2 Uni (io.smallrye.mutiny.Uni)2 KafkaCompanionTestBase (io.smallrye.reactive.messaging.kafka.base.KafkaCompanionTestBase)2 UnsatisfiedInstance (io.smallrye.reactive.messaging.kafka.base.UnsatisfiedInstance)2 ConsumerTask (io.smallrye.reactive.messaging.kafka.companion.ConsumerTask)2 KafkaCompanion (io.smallrye.reactive.messaging.kafka.companion.KafkaCompanion)2 JsonObjectSerializer (io.vertx.kafka.client.serialization.JsonObjectSerializer)2 Duration (java.time.Duration)2