use of io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class SourceBackPressureWithBrokerTest method myKafkaSourceConfig.
private KafkaMapBasedConfig myKafkaSourceConfig(String topic) {
KafkaMapBasedConfig config = kafkaConfig("mp.messaging.incoming.data");
config.put("value.deserializer", StringDeserializer.class.getName());
config.put("enable.auto.commit", "false");
config.put("auto.offset.reset", "earliest");
config.put("topic", topic);
config.put("max.poll.records", 1);
return config;
}
use of io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSinkWithCloudEventsTest method testSendingBinaryCloudEventsWithContentType.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testSendingBinaryCloudEventsWithContentType() {
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").withDataContentType("text/plain").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()), // Rules 3.2.1
new RecordHeader("ce_datacontenttype", "text/plain".getBytes()), new RecordHeader("content-type", "text/plain".getBytes()), new RecordHeader("ce_source", "test://test".getBytes()), new RecordHeader("ce_id", "some id".getBytes()));
assertThat(record.value()).isEqualTo("hello");
}
use of io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSinkWithCloudEventsTest method testSendingStructuredCloudEventsWithComplexPayload.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testSendingStructuredCloudEventsWithComplexPayload() {
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);
Pet neo = new Pet();
neo.name = "neo";
neo.kind = "rabbit";
Message<?> message = Message.of(neo).addMetadata(OutgoingCloudEventMetadata.builder().withSource(URI.create("test://test")).withType("type").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("type");
assertThat(json.getString("source")).isEqualTo("test://test");
assertThat(json.getString("id")).isEqualTo("some id");
assertThat(json.getJsonObject("data").getString("name")).isEqualTo("neo");
assertThat(json.getJsonObject("data").getString("kind")).isEqualTo("rabbit");
}
use of io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceBatchWithCloudEventsTest method testReceivingStructuredCloudEventsNoData.
@SuppressWarnings("unchecked")
@Test
public void testReceivingStructuredCloudEventsNoData() {
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.getBatchStream().subscribe().with(m -> messages.addAll(getRecordsFromBatchMessage(m)));
companion.produceStrings().fromRecords(new ProducerRecord<>(topic, null, null, null, new JsonObject().put("specversion", CloudEventMetadata.CE_VERSION_1_0).put("type", "type").put("id", "id").put("source", "test://test").encode(), Collections.singletonList(new RecordHeader("content-type", "application/cloudevents+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).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.getData()).isNull();
assertThat(message.getPayload()).isNull();
}
use of io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceBatchWithCloudEventsTest method testReceivingStructuredCloudEventsWithJsonObjectDeserializer.
@SuppressWarnings("unchecked")
@Test
public void testReceivingStructuredCloudEventsWithJsonObjectDeserializer() {
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.getBatchStream().subscribe().with(m -> messages.addAll(getRecordsFromBatchMessage(m)));
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("source", "test://test").put("subject", "foo").put("data", new JsonObject().put("name", "neo")), Collections.singletonList(new RecordHeader("content-type", "application/cloudevents+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).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.getTimeStamp()).isEmpty();
assertThat(metadata.getDataContentType()).isEmpty();
assertThat(metadata.getDataSchema()).isEmpty();
assertThat(metadata.getData().getString("name")).isEqualTo("neo");
// Extensions
assertThat(metadata.getKey()).isEqualTo("key");
// Rule 3.1 - partitionkey attribute
assertThat(metadata.<String>getExtension("partitionkey")).hasValue("key");
assertThat(metadata.getTopic()).isEqualTo(topic);
assertThat(message.getPayload()).isInstanceOf(JsonObject.class);
assertThat(((JsonObject) message.getPayload()).getString("name")).isEqualTo("neo");
}
Aggregations