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");
}
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);
}
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!");
}
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;
}
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!");
}
Aggregations