8547cf9a7e1a2c1def35c01b603c4fd394aebb1c
[smo/teiv.git] /
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Modifications Copyright (C) 2025 OpenInfra Foundation Europe
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20 package org.oran.smo.ncmp_to_teiv_adapter;
21
22 import io.cloudevents.CloudEvent;
23 import org.apache.kafka.clients.producer.ProducerConfig;
24 import org.apache.kafka.common.serialization.StringSerializer;
25 import io.cloudevents.kafka.CloudEventSerializer;
26 import org.springframework.beans.factory.annotation.Value;
27 import org.springframework.context.annotation.Bean;
28 import org.springframework.context.annotation.Configuration;
29 import org.springframework.kafka.core.DefaultKafkaProducerFactory;
30 import org.springframework.kafka.core.KafkaTemplate;
31 import org.springframework.kafka.core.ProducerFactory;
32
33 import java.util.HashMap;
34 import java.util.Map;
35
36 @Configuration
37 public class KafkaProducerConfig {
38
39     @Value("${spring.kafka.bootstrap-servers}")
40     private String bootstrapServer;
41
42     @Bean
43     public ProducerFactory<String, CloudEvent> producerFactory() {
44         Map<String, Object> configProps = new HashMap<>();
45         configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServer);
46         configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
47         configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, CloudEventSerializer.class);
48
49         return new DefaultKafkaProducerFactory<>(configProps);
50     }
51
52     @Bean
53     public KafkaTemplate<String, CloudEvent> kafkaTemplate() {
54         return new KafkaTemplate<>(producerFactory());
55     }
56 }