use of io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceWithCloudEventsTest method testReceivingStructuredCloudEventsWithoutSource.
@Test
public void testReceivingStructuredCloudEventsWithoutSource() {
KafkaMapBasedConfig config = newCommonConfig();
config.put("topic", topic);
config.put("value.deserializer", JsonObjectDeserializer.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.produce(String.class, JsonObject.class).fromRecords(new ProducerRecord<>(topic, null, null, "key", new JsonObject().put("specversion", CloudEventMetadata.CE_VERSION_1_0).put("type", "type").put("id", "id").put("subject", "foo").put("data", new JsonObject().put("name", "neo")), Collections.singletonList(new RecordHeader("content-type", "application/cloudevents+json; charset=utf-8".getBytes()))));
await().pollDelay(Duration.ofSeconds(1)).atMost(2, TimeUnit.MINUTES).until(() -> messages.size() == 0);
// Nothing has been received because the deserializer is not supported.
}
use of io.smallrye.reactive.messaging.kafka.KafkaConnectorIncomingConfiguration in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceWithCloudEventsTest method testReceivingBinaryCloudEventsWithoutKey.
@SuppressWarnings("unchecked")
@Test
public void testReceivingBinaryCloudEventsWithoutKey() {
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);
List<Header> headers = new ArrayList<>();
headers.add(new RecordHeader("ce_specversion", CloudEventMetadata.CE_VERSION_1_0.getBytes()));
headers.add(new RecordHeader("ce_type", "type".getBytes()));
headers.add(new RecordHeader("ce_source", "test://test".getBytes()));
headers.add(new RecordHeader("ce_id", "id".getBytes()));
headers.add(new RecordHeader("ce_time", "2020-07-23T07:59:04Z".getBytes()));
headers.add(new RecordHeader("content-type", "text/plain".getBytes()));
headers.add(new RecordHeader("ce_subject", "foo".getBytes()));
headers.add(new RecordHeader("ce_dataschema", "http://schema.io".getBytes()));
headers.add(new RecordHeader("ce_ext", "bar".getBytes()));
headers.add(new RecordHeader("some-header", "baz".getBytes()));
companion.produceStrings().fromRecords(new ProducerRecord<>(topic, null, null, null, "Hello World", headers));
await().atMost(2, TimeUnit.MINUTES).until(() -> messages.size() >= 1);
Message<?> message = messages.get(0);
IncomingKafkaCloudEventMetadata<String, String> metadata = message.getMetadata(IncomingKafkaCloudEventMetadata.class).orElse(null);
assertThat(metadata).isNotNull();
assertThat(metadata.getSpecVersion()).isEqualTo(CloudEventMetadata.CE_VERSION_1_0);
assertThat(metadata.getType()).isEqualTo("type");
assertThat(metadata.getId()).isEqualTo("id");
assertThat(metadata.getSource()).isEqualTo(URI.create("test://test"));
assertThat(metadata.getSubject()).hasValue("foo");
assertThat(metadata.getDataSchema()).hasValue(URI.create("http://schema.io"));
assertThat(metadata.getTimeStamp()).isNotEmpty();
assertThat(metadata.getData()).isEqualTo("Hello World");
// Rule 3.2.1 - the content-type must be mapped to the datacontenttype attribute
assertThat(metadata.getDataContentType()).hasValue("text/plain");
// Rule 3.2.3
assertThat(metadata.getExtension("ext")).hasValue("bar");
assertThat(metadata.getExtension("some-header")).isEmpty();
// Extensions
assertThat(metadata.getKey()).isNull();
// Rule 3.1 - partitionkey attribute
assertThat(metadata.<String>getExtension("partitionkey")).isEmpty();
assertThat(metadata.getTopic()).isEqualTo(topic);
assertThat(message.getPayload()).isInstanceOf(String.class).isEqualTo("Hello World");
}
Aggregations