use of io.smallrye.reactive.messaging.kafka.KafkaConnectorOutgoingConfiguration in project smallrye-reactive-messaging by smallrye.
the class KafkaSinkWithCloudEventsTest method testSendingStructuredCloudEventsWithWrongSerializer.
@Test
public void testSendingStructuredCloudEventsWithWrongSerializer() {
KafkaMapBasedConfig config = newCommonConfig();
config.put("topic", topic);
config.put("value.serializer", DoubleSerializer.class.getName());
config.put("channel-name", topic);
config.put("cloud-events-mode", "structured");
KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
assertThatThrownBy(() -> new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance())).isInstanceOf(IllegalStateException.class);
}
use of io.smallrye.reactive.messaging.kafka.KafkaConnectorOutgoingConfiguration in project smallrye-reactive-messaging by smallrye.
the class ReactiveKafkaProducerTest method createSink.
public KafkaSink createSink() {
MapBasedConfig config = createProducerConfig().put("channel-name", "test-" + ThreadLocalRandom.current().nextInt()).put("topic", topic);
KafkaSink sink = new KafkaSink(new KafkaConnectorOutgoingConfiguration(config), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());
this.sinks.add(sink);
return sink;
}
use of io.smallrye.reactive.messaging.kafka.KafkaConnectorOutgoingConfiguration 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.KafkaConnectorOutgoingConfiguration 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.KafkaConnectorOutgoingConfiguration 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");
}
Aggregations