use of io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig 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.base.KafkaMapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class BatchConsumerTest method testIncomingConsumingMessageWithMetadata.
@Test
void testIncomingConsumingMessageWithMetadata() {
String newTopic = UUID.randomUUID().toString();
companion.topics().createAndWait(newTopic, 3);
KafkaMapBasedConfig config = kafkaConfig("mp.messaging.incoming.kafka").put("value.deserializer", StringDeserializer.class.getName()).put("auto.offset.reset", "earliest").put("topic", newTopic).put("batch", true);
BeanConsumingMessageWithBatchMetadata bean = runApplication(config, BeanConsumingMessageWithBatchMetadata.class);
companion.produceStrings().usingGenerator(i -> new ProducerRecord<>(newTopic, "k-" + i, "v-" + i), 10);
await().until(() -> bean.metadata().stream().mapToInt(m -> m.getRecords().count()).sum() == 10);
Map<TopicPartition, List<ConsumerRecord<String, String>>> records = new HashMap<>();
for (IncomingKafkaRecordBatchMetadata<String, String> metadata : bean.metadata()) {
for (TopicPartition partition : metadata.getRecords().partitions()) {
List<ConsumerRecord<String, String>> list = records.computeIfAbsent(partition, p -> new ArrayList<>());
list.addAll(metadata.getRecords().records(partition));
}
}
assertThat(records.keySet()).hasSize(3);
assertThat(records.values()).flatMap(l -> l).hasSize(10).allSatisfy(r -> {
assertThat(r.value()).startsWith("v-");
assertThat(r.key()).startsWith("k");
});
}
use of io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class BatchConsumerTest method testIncomingConsumingKafkaBatchRecords.
@Test
void testIncomingConsumingKafkaBatchRecords() {
KafkaMapBasedConfig config = kafkaConfig("mp.messaging.incoming.kafka").put("value.deserializer", StringDeserializer.class.getName()).put("auto.offset.reset", "earliest").put("topic", topic).put("batch", true);
BeanConsumingKafkaRecordBatch bean = runApplication(config, BeanConsumingKafkaRecordBatch.class);
companion.produceStrings().usingGenerator(i -> new ProducerRecord<>(topic, "k-" + i, "v-" + i), 10);
await().until(() -> bean.messages().size() == 10);
assertThat(bean.messages()).hasSize(10).allSatisfy(r -> {
assertThat(r.getKey()).startsWith("k-");
assertThat(r.getPayload()).startsWith("v-");
});
}
use of io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class RetryTest method getConfig.
private KafkaMapBasedConfig getConfig(String topic) {
KafkaMapBasedConfig config = kafkaConfig("mp.messaging.incoming.kafka");
config.put("group.id", UUID.randomUUID().toString());
config.put("topic", topic);
config.put("value.deserializer", StringDeserializer.class.getName());
config.put("enable.auto.commit", "false");
config.put("auto.offset.reset", "earliest");
config.put("failure-strategy", "ignore");
return config;
}
use of io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class HealthCheckTest method testHealthOfApplicationWithChannel.
@Test
public void testHealthOfApplicationWithChannel() {
KafkaMapBasedConfig config = getKafkaSourceConfig(topic);
LazyConsumingBean bean = runApplication(config, LazyConsumingBean.class);
ProducerTask produced = companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, "key", i), 10);
await().until(this::isStarted);
await().until(this::isReady);
await().until(this::isAlive);
produced.awaitCompletion(Duration.ofMinutes(1));
Multi<Integer> channel = bean.getChannel();
channel.select().first(10).collect().asList().await().atMost(Duration.ofSeconds(10));
HealthReport startup = getHealth().getStartup();
HealthReport liveness = getHealth().getLiveness();
HealthReport readiness = getHealth().getReadiness();
assertThat(startup.isOk()).isTrue();
assertThat(liveness.isOk()).isTrue();
assertThat(readiness.isOk()).isTrue();
assertThat(startup.getChannels()).hasSize(1);
assertThat(liveness.getChannels()).hasSize(1);
assertThat(readiness.getChannels()).hasSize(1);
}
Aggregations