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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.oran.smo.ncmp_to_teiv_adapter;
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;
33 import java.util.HashMap;
37 public class KafkaProducerConfig {
39 @Value("${spring.kafka.bootstrap-servers}")
40 private String bootstrapServer;
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);
49 return new DefaultKafkaProducerFactory<>(configProps);
53 public KafkaTemplate<String, CloudEvent> kafkaTemplate() {
54 return new KafkaTemplate<>(producerFactory());