Search in sources :

Example 51 with KafkaMapBasedConfig

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

the class KafkaSinkWithCloudEventsTest method testSendingBinaryCloudEventsWithKey.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testSendingBinaryCloudEventsWithKey() {
    KafkaMapBasedConfig config = newCommonConfig();
    config.put("topic", topic);
    config.put("value.serializer", StringSerializer.class.getName());
    config.put("channel-name", topic);
    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().withSource(URI.create("test://test")).withType("type").withId("some id").withExtension("partitionkey", "my-key").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", "type".getBytes()), new RecordHeader("ce_source", "test://test".getBytes()), new RecordHeader("ce_partitionkey", "my-key".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)

Example 52 with KafkaMapBasedConfig

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

the class KafkaSinkWithCloudEventsTest method testSendingStructuredCloudEventsWithConfiguredTypeAndSource.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testSendingStructuredCloudEventsWithConfiguredTypeAndSource() {
    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!").addMetadata(OutgoingCloudEventMetadata.builder().withId("some id").build());
    Multi.createFrom().<Message<?>>item(message).subscribe().withSubscriber((Subscriber) sink.getSink().build());
    await().until(() -> records.count() == 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")).isEqualTo("some id");
    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 53 with KafkaMapBasedConfig

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

the class KafkaSinkWithCloudEventsTest method testSendingBinaryCloudEventsWithExtensions.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testSendingBinaryCloudEventsWithExtensions() {
    KafkaMapBasedConfig config = newCommonConfig();
    config.put("topic", topic);
    config.put("value.serializer", StringSerializer.class.getName());
    config.put("channel-name", topic);
    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().withSource(URI.create("test://test")).withType("type").withId("some id").withExtension("ext", 124).withExtension("ext2", "bonjour").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()).isNull();
    assertThat(record.headers()).contains(new RecordHeader("ce_specversion", "1.0".getBytes()), new RecordHeader("ce_type", "type".getBytes()), new RecordHeader("ce_source", "test://test".getBytes()), new RecordHeader("ce_id", "some id".getBytes()), new RecordHeader("ce_ext", "124".getBytes()), new RecordHeader("ce_ext2", "bonjour".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)

Example 54 with KafkaMapBasedConfig

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

the class KafkaSinkWithCloudEventsTest method testSendingStructuredCloudEventsWithExtensions.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testSendingStructuredCloudEventsWithExtensions() {
    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");
    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().withSource(URI.create("test://test")).withType("type").withId("some id").withExtension("ext", 123).withExtension("ext2", "dddd").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()).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("type");
    assertThat(json.getString("source")).isEqualTo("test://test");
    assertThat(json.getString("id")).isEqualTo("some id");
    assertThat(json.getString("ext2")).isEqualTo("dddd");
    assertThat(json.getInteger("ext")).isEqualTo(123);
    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 55 with KafkaMapBasedConfig

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

the class KafkaSinkWithCloudEventsTest method testWithCloudEventDisabled.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testWithCloudEventDisabled() {
    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", false);
    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().lastHeader("ce_specversion")).isNull();
    assertThat(record.headers().lastHeader("ce_id")).isNull();
    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) 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