use of org.sdase.commons.server.kafka.consumer.IgnoreAndProceedErrorHandler in project sda-dropwizard-commons by SDA-SE.
the class KafkaBundleWithConfigIT method multiTest.
@Test
public void multiTest() {
final String TOPIC_CREATE = "create";
final String TOPIC_DELETE = "delete";
KAFKA.getKafkaTestUtils().createTopic(TOPIC_CREATE, 1, (short) 1);
KAFKA.getKafkaTestUtils().createTopic(TOPIC_DELETE, 1, (short) 1);
kafkaBundle.createMessageListener(MessageListenerRegistration.builder().withDefaultListenerConfig().forTopic(TOPIC_CREATE).withDefaultConsumer().withKeyDeserializer(new LongDeserializer()).withListenerStrategy(new SyncCommitMLS<Long, String>(record -> resultsString.add(record.value()), new IgnoreAndProceedErrorHandler<>())).build());
kafkaBundle.createMessageListener(MessageListenerRegistration.builder().withDefaultListenerConfig().forTopic(TOPIC_DELETE).withDefaultConsumer().withListenerStrategy(new SyncCommitMLS<String, String>(record -> resultsString.add(record.value()), new IgnoreAndProceedErrorHandler<>())).build());
MessageProducer<Long, String> createProducer = kafkaBundle.registerProducer(ProducerRegistration.<Long, String>builder().forTopic(TOPIC_CREATE).withProducerConfig(new ProducerConfig()).withKeySerializer(new LongSerializer()).build());
MessageProducer<String, String> deleteProducer = kafkaBundle.registerProducer(ProducerRegistration.<String, String>builder().forTopic(TOPIC_DELETE).withDefaultProducer().build());
createProducer.send(1L, "test1");
deleteProducer.send("key", "test2");
await().atMost(KafkaBundleConsts.N_MAX_WAIT_MS, MILLISECONDS).until(() -> resultsString.size() == 2);
assertThat(resultsString).containsExactlyInAnyOrder("test1", "test2");
}
use of org.sdase.commons.server.kafka.consumer.IgnoreAndProceedErrorHandler in project sda-dropwizard-commons by SDA-SE.
the class KafkaBundleWithConfigIT method testJsonSerializer.
@Test
public void testJsonSerializer() {
String topic = "testJsonSerializer";
KAFKA.getKafkaTestUtils().createTopic(topic, 1, (short) 1);
kafkaBundle.createMessageListener(MessageListenerRegistration.builder().withDefaultListenerConfig().forTopic(topic).withDefaultConsumer().withValueDeserializer(new KafkaJsonDeserializer<>(new ObjectMapper(), SimpleEntity.class)).withListenerStrategy(new SyncCommitMLS<>(x -> resultsString.add(x.value().getName()), new IgnoreAndProceedErrorHandler<>())).build());
MessageProducer<Object, SimpleEntity> prod = kafkaBundle.registerProducer(ProducerRegistration.builder().forTopic(topic).withDefaultProducer().withValueSerializer(new KafkaJsonSerializer<SimpleEntity>(new ObjectMapper())).build());
SimpleEntity a = new SimpleEntity();
a.setName("a");
SimpleEntity b = new SimpleEntity();
b.setName("b");
prod.send("Test", a);
prod.send("Test", b);
await().atMost(KafkaBundleConsts.N_MAX_WAIT_MS, MILLISECONDS).until(() -> resultsString.size() == 2);
assertThat(resultsString).containsExactlyInAnyOrder("a", "b");
}
use of org.sdase.commons.server.kafka.consumer.IgnoreAndProceedErrorHandler in project sda-dropwizard-commons by SDA-SE.
the class KafkaBundleWithConfigIT method testKafkaMessages.
@Test
public void testKafkaMessages() {
String topic = "testKafkaMessages";
List<String> checkMessages = new ArrayList<>();
KAFKA.getKafkaTestUtils().createTopic(topic, 1, (short) 1);
kafkaBundle.createMessageListener(MessageListenerRegistration.builder().withDefaultListenerConfig().forTopic(topic).withDefaultConsumer().withKeyDeserializer(new StringDeserializer()).withValueDeserializer(new StringDeserializer()).withListenerStrategy(new SyncCommitMLS<>(record -> resultsString.add(record.value()), new IgnoreAndProceedErrorHandler<>())).build());
// pass in messages
for (int i = 0; i < KafkaBundleConsts.N_MESSAGES; i++) {
String message = UUID.randomUUID().toString();
checkMessages.add(message);
stringStringProducer.send(new ProducerRecord<>(topic, message));
}
await().atMost(KafkaBundleConsts.N_MAX_WAIT_MS, MILLISECONDS).until(() -> resultsString.size() == checkMessages.size());
assertThat(resultsString).containsExactlyInAnyOrderElementsOf(checkMessages);
}
use of org.sdase.commons.server.kafka.consumer.IgnoreAndProceedErrorHandler in project sda-dropwizard-commons by SDA-SE.
the class KafkaBundleWithConfigIT method kafkaConsumerReceivesMessages.
@Test
public void kafkaConsumerReceivesMessages() {
String topic = "kafkaConsumerReceivesMessages";
KAFKA.getKafkaTestUtils().createTopic(topic, 1, (short) 1);
StringDeserializer deserializer = new StringDeserializer();
kafkaBundle.createMessageListener(MessageListenerRegistration.builder().withDefaultListenerConfig().forTopic(topic).withDefaultConsumer().withKeyDeserializer(deserializer).withValueDeserializer(deserializer).withListenerStrategy(new SyncCommitMLS<>(record -> resultsString.add(record.value()), new IgnoreAndProceedErrorHandler<>())).build());
List<String> checkMessages = new ArrayList<>();
// pass in messages
for (int i = 0; i < KafkaBundleConsts.N_MESSAGES; i++) {
String message = UUID.randomUUID().toString();
checkMessages.add(message);
stringStringProducer.send(new ProducerRecord<>(topic, message));
}
await().atMost(KafkaBundleConsts.N_MAX_WAIT_MS, MILLISECONDS).until(() -> resultsString.size() == checkMessages.size());
assertThat(resultsString).containsExactlyElementsOf(checkMessages);
}
Aggregations