2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.netconfsimulator.kafka;
25 import org.apache.kafka.clients.consumer.ConsumerConfig;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.context.annotation.Bean;
28 import org.springframework.context.annotation.Configuration;
29 import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
30 import org.springframework.kafka.core.ConsumerFactory;
31 import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
32 import org.springframework.kafka.core.DefaultKafkaProducerFactory;
33 import org.springframework.kafka.core.KafkaTemplate;
34 import org.springframework.kafka.core.ProducerFactory;
35 import org.springframework.kafka.test.utils.KafkaTestUtils;
37 import static org.onap.netconfsimulator.kafka.StoreServiceTest.embeddedKafka;
40 class EmbeddedKafkaConfig {
43 KafkaTemplate<String, String> kafkaTemplate(){
44 return new KafkaTemplate<>(producerFactory());
49 ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory(ConsumerFactory<String, String> consumerFactory){
50 ConcurrentKafkaListenerContainerFactory<String, String> containerFactory = new ConcurrentKafkaListenerContainerFactory<>();
51 containerFactory.setConsumerFactory(consumerFactory);
52 return containerFactory;
56 ConsumerFactory<String, String> consumerFactory(){
57 Map<String, Object> consumerProperties =
58 KafkaTestUtils.consumerProps("sender", "false", embeddedKafka.getEmbeddedKafka());
59 consumerProperties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
60 return new DefaultKafkaConsumerFactory<>(consumerProperties);
63 private ProducerFactory<String, String> producerFactory() {
64 Map<String, Object> senderProperties =
65 KafkaTestUtils.senderProps(embeddedKafka.getEmbeddedKafka().getBrokersAsString());
66 return new DefaultKafkaProducerFactory<>(senderProperties);