Search in sources :

Example 11 with KafkaMapBasedConfig

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

the class KafkaSourceWithCloudEventsTest method testReceivingStructuredCloudEventsWithoutMatchingContentTypeIsNotReadACloudEvent.

@SuppressWarnings("unchecked")
@Test
public void testReceivingStructuredCloudEventsWithoutMatchingContentTypeIsNotReadACloudEvent() {
    KafkaMapBasedConfig config = newCommonConfig();
    config.put("topic", topic);
    config.put("value.deserializer", StringDeserializer.class.getName());
    config.put("channel-name", topic);
    KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
    source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
    List<Message<?>> messages = new ArrayList<>();
    source.getStream().subscribe().with(messages::add);
    companion.produceStrings().fromRecords(new ProducerRecord<>(topic, null, null, "key", new JsonObject().put("specversion", CloudEventMetadata.CE_VERSION_1_0).put("type", "type").put("id", "id").put("source", "test://test").put("data", new JsonObject().put("name", "neo")).encode(), Collections.singletonList(new RecordHeader("content-type", "application/json; charset=utf-8".getBytes()))));
    await().atMost(2, TimeUnit.MINUTES).until(() -> messages.size() >= 1);
    Message<?> message = messages.get(0);
    IncomingKafkaCloudEventMetadata<String, JsonObject> metadata = message.getMetadata(IncomingKafkaCloudEventMetadata.class).orElse(null);
    assertThat(metadata).isNull();
    CloudEventMetadata<JsonObject> metadata2 = message.getMetadata(CloudEventMetadata.class).orElse(null);
    assertThat(metadata2).isNull();
    assertThat(message.getPayload()).isInstanceOf(String.class);
    JsonObject json = new JsonObject(message.getPayload().toString());
    assertThat(json.getString("id")).isEqualTo("id");
}
Also used : Message(org.eclipse.microprofile.reactive.messaging.Message) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) JsonObject(io.vertx.core.json.JsonObject) CloudEventMetadata(io.smallrye.reactive.messaging.ce.CloudEventMetadata) IncomingKafkaCloudEventMetadata(io.smallrye.reactive.messaging.kafka.IncomingKafkaCloudEventMetadata) IncomingKafkaCloudEventMetadata(io.smallrye.reactive.messaging.kafka.IncomingKafkaCloudEventMetadata) KafkaConnectorIncomingConfiguration(io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration) RecordHeader(org.apache.kafka.common.header.internals.RecordHeader) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 12 with KafkaMapBasedConfig

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

the class KafkaSinkWithLegacyMetadataTest method testConnectorWithMultipleUpstreams.

@Test
public void testConnectorWithMultipleUpstreams() {
    ConsumerTask<String, Integer> consume = companion.consumeIntegers().fromTopics(topic, 20);
    KafkaMapBasedConfig config = getKafkaSinkConfigWithMultipleUpstreams(topic);
    runApplication(config, BeanWithMultipleUpstreams.class);
    await().until(this::isReady);
    await().until(this::isAlive);
    assertThat(consume.awaitCompletion(Duration.ofMinutes(1)).count()).isEqualTo(20);
    assertThat(consume.getRecords()).extracting(ConsumerRecord::value).contains(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19);
}
Also used : KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 13 with KafkaMapBasedConfig

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

the class KafkaSinkWithCloudEventsTest method testSendingStructuredCloudEventsWithConfiguredTypeAndSourceAndNoCloudEventMetadata.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testSendingStructuredCloudEventsWithConfiguredTypeAndSourceAndNoCloudEventMetadata() {
    KafkaMapBasedConfig config = newCommonConfig();
    config.put("topic", topic);
    config.put("value.serializer", StringSerializer.class.getName());
    config.put("channel-name", topic);
    config.put("cloud-events-mode", "structured");
    config.put("cloud-events-type", "my type");
    config.put("cloud-events-source", "http://acme.org");
    KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
    sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());
    ConsumerTask<String, String> records = companion.consumeStrings().fromTopics(topic);
    Message<?> message = Message.of("hello!");
    Multi.createFrom().<Message<?>>item(message).subscribe().withSubscriber((Subscriber) sink.getSink().build());
    await().until(() -> records.getRecords().size() == 1);
    ConsumerRecord<String, String> record = records.getRecords().get(0);
    assertThat(record.topic()).isEqualTo(topic);
    assertThat(record.key()).isNull();
    assertThat(record.headers()).contains(new RecordHeader("content-type", "application/cloudevents+json; charset=UTF-8".getBytes()));
    JsonObject json = new JsonObject(record.value());
    assertThat(json.getString("specversion")).isEqualTo("1.0");
    assertThat(json.getString("type")).isEqualTo("my type");
    assertThat(json.getString("source")).isEqualTo("http://acme.org");
    assertThat(json.getString("id")).isNotNull();
    assertThat(json.getString("data")).isEqualTo("hello!");
}
Also used : Message(org.eclipse.microprofile.reactive.messaging.Message) KafkaSink(io.smallrye.reactive.messaging.kafka.impl.KafkaSink) JsonObject(io.vertx.core.json.JsonObject) KafkaConnectorOutgoingConfiguration(io.smallrye.reactive.messaging.kafka.KafkaConnectorOutgoingConfiguration) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) RecordHeader(org.apache.kafka.common.header.internals.RecordHeader) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 14 with KafkaMapBasedConfig

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

the class KafkaSinkWithCloudEventsTest method getConfigToSendBinaryCloudEventsWithDefault.

private KafkaMapBasedConfig getConfigToSendBinaryCloudEventsWithDefault() {
    KafkaMapBasedConfig config = kafkaConfig("mp.messaging.outgoing.source");
    config.put("value.serializer", StringSerializer.class.getName());
    config.put("topic", topic);
    config.put("cloud-events-type", "greetings");
    config.put("cloud-events-source", "source://me");
    config.put("cloud-events-subject", "test");
    return config;
}
Also used : StringSerializer(org.apache.kafka.common.serialization.StringSerializer) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)

Example 15 with KafkaMapBasedConfig

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

the class KafkaSinkWithCloudEventsTest method testSendingBinaryCloudEventsWithConfiguredTypeAndSource.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testSendingBinaryCloudEventsWithConfiguredTypeAndSource() {
    KafkaMapBasedConfig config = newCommonConfig();
    config.put("topic", topic);
    config.put("value.serializer", StringSerializer.class.getName());
    config.put("channel-name", topic);
    config.put("key", "my-key");
    config.put("cloud-events-type", "my type");
    config.put("cloud-events-source", "http://acme.org");
    KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
    sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());
    ConsumerTask<String, String> records = companion.consumeStrings().fromTopics(topic);
    Message<?> message = Message.of("hello!").addMetadata(OutgoingCloudEventMetadata.builder().withId("some id").build());
    Multi.createFrom().<Message<?>>item(message).subscribe().withSubscriber((Subscriber) sink.getSink().build());
    await().until(() -> records.getRecords().size() == 1);
    ConsumerRecord<String, String> record = records.getRecords().get(0);
    assertThat(record.topic()).isEqualTo(topic);
    assertThat(record.key()).isEqualTo("my-key");
    assertThat(record.headers()).contains(new RecordHeader("ce_specversion", "1.0".getBytes()), new RecordHeader("ce_type", "my type".getBytes()), new RecordHeader("ce_source", "http://acme.org".getBytes()), new RecordHeader("ce_id", "some id".getBytes()));
    assertThat(record.value()).isEqualTo("hello!");
}
Also used : Message(org.eclipse.microprofile.reactive.messaging.Message) KafkaSink(io.smallrye.reactive.messaging.kafka.impl.KafkaSink) KafkaConnectorOutgoingConfiguration(io.smallrye.reactive.messaging.kafka.KafkaConnectorOutgoingConfiguration) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) RecordHeader(org.apache.kafka.common.header.internals.RecordHeader) 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