use of io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class ConsumerRecordConverterTest method testChannelBeanUsingConverter.
@Test
public void testChannelBeanUsingConverter() {
KafkaMapBasedConfig builder = kafkaConfig("mp.messaging.incoming.data");
builder.put("value.deserializer", StringDeserializer.class.getName());
builder.put("auto.offset.reset", "earliest");
builder.put("topic", topic);
addBeans(ConsumerRecordConverter.class, RecordConverter.class);
MyChannelBean bean = runApplication(builder, MyChannelBean.class);
bean.consume();
companion.produceStrings().usingGenerator(i -> new ProducerRecord<>(topic, i % 2 == 0 ? "key" : "k", "v-" + i), 10);
await().until(() -> bean.list().size() == 10);
assertThat(bean.list()).hasSize(10).allSatisfy(r -> {
assertThat(r.value()).startsWith("v-");
assertThat(r.key()).startsWith("k");
if (!r.key().equalsIgnoreCase("key")) {
assertThat(r.key()).isEqualTo("k");
}
});
}
use of io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class ConsumerRecordsConverterTest method testBeanUsingConverter.
@Test
public void testBeanUsingConverter() {
KafkaMapBasedConfig builder = kafkaConfig("mp.messaging.incoming.data");
builder.put("value.deserializer", StringDeserializer.class.getName());
builder.put("auto.offset.reset", "earliest");
builder.put("topic", topic);
builder.put("batch", true);
addBeans(ConsumerRecordsConverter.class);
MyBean bean = runApplication(builder, MyBean.class);
companion.produceStrings().usingGenerator(i -> new ProducerRecord<>(topic, i % 2 == 0 ? "key" : "k", "v-" + i), 10);
await().until(() -> bean.list().stream().mapToInt(ConsumerRecords::count).sum() == 10);
List<ConsumerRecord<String, String>> consumerRecords = bean.list().stream().flatMap(r -> StreamSupport.stream(r.records(topic).spliterator(), false)).collect(Collectors.toList());
assertThat(consumerRecords).hasSize(10).allSatisfy(r -> {
assertThat(r.value()).startsWith("v-");
assertThat(r.key()).startsWith("k");
if (!r.key().equalsIgnoreCase("key")) {
assertThat(r.key()).isEqualTo("k");
}
});
}
use of io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class CustomConverterTest method testBeanUsingCustomConverter.
@Test
public void testBeanUsingCustomConverter() {
KafkaMapBasedConfig builder = kafkaConfig("mp.messaging.incoming.data");
builder.put("value.deserializer", StringDeserializer.class.getName());
builder.put("auto.offset.reset", "earliest");
builder.put("topic", topic);
addBeans(ConsumerRecordConverter.class, RecordConverter.class, MyConverter.class);
MyBean bean = runApplication(builder, MyBean.class);
companion.produceStrings().usingGenerator(i -> new ProducerRecord<>(topic, i % 2 == 0 ? "key" : "k", "v-" + i), 10);
await().until(() -> bean.list().size() == 10);
assertThat(bean.list()).hasSize(10).allSatisfy(r -> {
assertThat(r.getItem1()).isEqualTo(topic);
assertThat(r.getItem3()).startsWith("v-");
assertThat(r.getItem2()).startsWith("k");
if (!r.getItem2().equalsIgnoreCase("key")) {
assertThat(r.getItem2()).isEqualTo("k");
}
});
}
use of io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceWithCloudEventsTest method testReceivingStructuredCloudEventsWithByteArrayDeserializer.
@SuppressWarnings("unchecked")
@Test
public void testReceivingStructuredCloudEventsWithByteArrayDeserializer() {
KafkaMapBasedConfig config = newCommonConfig();
config.put("topic", topic);
config.put("value.deserializer", ByteArrayDeserializer.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("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.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");
}
use of io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceWithCloudEventsTest method getConfig.
private KafkaMapBasedConfig getConfig(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);
return config;
}
Aggregations