use of org.sdase.commons.server.kafka.config.ProducerConfig in project sda-dropwizard-commons by SDA-SE.
the class ProducerRegistrationTest method customProducerCanBeUsed.
@Test
public void customProducerCanBeUsed() {
Map<String, String> test = new HashMap<>();
test.put("key.serializer", StringSerializer.class.getName());
test.put("value.serializer", StringSerializer.class.getName());
test.put("bootstrap.servers", "localhost:9092");
ProducerConfig producerConfig = new ProducerConfig();
producerConfig.getConfig().putAll(test);
ProducerRegistration<String, String> producerRegistration = ProducerRegistration.<String, String>builder().forTopic("TOPIC").withProducerConfig(producerConfig).build();
assertThat(producerRegistration).isNotNull();
assertThat(producerRegistration.getTopic().getTopicName()).isEqualTo("TOPIC");
assertThat(producerRegistration.getProducerConfig()).isEqualTo(producerConfig);
}
use of org.sdase.commons.server.kafka.config.ProducerConfig 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");
}
Aggregations