use of io.smallrye.reactive.messaging.kafka.impl.KafkaSink in project smallrye-reactive-messaging by smallrye.
the class KafkaConnector method getSubscriberBuilder.
@Override
public SubscriberBuilder<? extends Message<?>, Void> getSubscriberBuilder(Config config) {
Config channelConfiguration = ConfigHelper.retrieveChannelConfiguration(configurations, config);
KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(channelConfiguration);
// log deprecated config
if (oc.getHealthReadinessTopicVerification().isPresent()) {
log.deprecatedConfig("health-readiness-topic-verification", "health-topic-verification-enabled");
}
if (oc.getHealthReadinessTimeout().isPresent()) {
log.deprecatedConfig("health-readiness-timeout", "health-topic-verification-timeout");
}
KafkaSink sink = new KafkaSink(oc, kafkaCDIEvents, serializationFailureHandlers);
sinks.add(sink);
return sink.getSink();
}
use of io.smallrye.reactive.messaging.kafka.impl.KafkaSink in project smallrye-reactive-messaging by smallrye.
the class SerializerConfigurationTest method testFailureWhenValueSerializerIsNotSet.
@Test
public void testFailureWhenValueSerializerIsNotSet() {
MapBasedConfig config = commonConsumerConfiguration().without("value.serializer");
assertThatThrownBy(() -> {
sink = new KafkaSink(new KafkaConnectorOutgoingConfiguration(config), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());
}).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("value.serializer");
}
use of io.smallrye.reactive.messaging.kafka.impl.KafkaSink in project smallrye-reactive-messaging by smallrye.
the class SerializerConfigurationTest method testFailureWhenSerializerFailsDuringConfiguration.
@Test
public void testFailureWhenSerializerFailsDuringConfiguration() {
MapBasedConfig config = commonConsumerConfiguration().with("value.serializer", BrokenSerializerFailingDuringConfig.class.getName());
assertThatThrownBy(() -> {
sink = new KafkaSink(new KafkaConnectorOutgoingConfiguration(config), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());
}).isInstanceOf(KafkaException.class).hasCauseInstanceOf(IllegalStateException.class).hasStackTraceContaining("boom");
}
use of io.smallrye.reactive.messaging.kafka.impl.KafkaSink in project smallrye-reactive-messaging by smallrye.
the class SerializerConfigurationTest method testValueSerializationFailure.
@Test
public void testValueSerializationFailure() {
MapBasedConfig config = commonConsumerConfiguration().with("value.serializer", JsonObjectSerializer.class.getName()).with("key.serializer", JsonObjectSerializer.class.getName()).with("retries", 0L);
sink = new KafkaSink(new KafkaConnectorOutgoingConfiguration(config), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());
Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
AtomicBoolean nacked = new AtomicBoolean();
Multi.createFrom().items(Message.of(of(new JsonObject().put("k", "v"), 125.25)).withNack(t -> {
nacked.set(true);
return CompletableFuture.completedFuture(null);
})).subscribe((Subscriber<? super Message<?>>) subscriber);
await().until(nacked::get);
}
use of io.smallrye.reactive.messaging.kafka.impl.KafkaSink in project smallrye-reactive-messaging by smallrye.
the class KafkaSinkWithLegacyMetadataTest method testInvalidPayloadType.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testInvalidPayloadType() {
ConsumerTask<String, Integer> consumed = companion.consumeIntegers().fromTopics(topic, 4, Duration.ofSeconds(10));
MapBasedConfig config = getBaseConfig().with("topic", topic).with("value.serializer", IntegerSerializer.class.getName()).with("partition", 0).with("max-inflight-messages", 1L).with("channel-name", "my-channel").with("retries", // disable retry.
0L);
KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
CountKafkaCdiEvents testCdiEvents = new CountKafkaCdiEvents();
sink = new KafkaSink(oc, testCdiEvents, UnsatisfiedInstance.instance());
await().until(() -> {
HealthReport.HealthReportBuilder builder = HealthReport.builder();
sink.isReady(builder);
return builder.build().isOk();
});
List<Object> acked = new CopyOnWriteArrayList<>();
List<Object> nacked = new CopyOnWriteArrayList<>();
Subscriber subscriber = sink.getSink().build();
Multi.createFrom().range(0, 6).map(i -> {
if (i == 3 || i == 5) {
return Integer.toString(i);
}
return i;
}).map(i -> Message.of(i, () -> {
acked.add(i);
return CompletableFuture.completedFuture(null);
}, t -> {
nacked.add(i);
return CompletableFuture.completedFuture(null);
})).subscribe(subscriber);
// 3 and 5 are ignored.
assertThat(consumed.awaitCompletion(Duration.ofMinutes(1)).count()).isEqualTo(4);
await().until(() -> nacked.size() >= 2);
assertThat(acked).containsExactly(0, 1, 2, 4);
assertThat(nacked).contains("3", "5");
assertThat(testCdiEvents.firedConsumerEvents.sum()).isEqualTo(0);
assertThat(testCdiEvents.firedProducerEvents.sum()).isEqualTo(1);
}
Aggregations