2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2023 Nordix Foundation. 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.dmaap.kafka.sample;
23 import java.util.List;
24 import org.apache.kafka.clients.producer.RecordMetadata;
25 import org.onap.dmaap.kafka.OnapKafkaClient;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.boot.CommandLineRunner;
30 import org.springframework.boot.SpringApplication;
31 import org.springframework.boot.autoconfigure.SpringBootApplication;
33 @SpringBootApplication
34 public class Main implements CommandLineRunner{
36 private final Logger log = LoggerFactory.getLogger(OnapKafkaClient.class.getName());
39 private SampleConfiguration configuration;
41 public static void main(String[] args) {
42 SpringApplication.run(Main.class, args);
46 public void run(String... args) throws InterruptedException {
47 OnapKafkaClient handler = new OnapKafkaClient(configuration);
48 String testTopic = configuration.getConsumerTopics().get(0);
49 for (int i = 0; i < 5; i++) {
50 RecordMetadata recordMetadata = handler.publishToTopic(testTopic, "dummy-message-"+i);
51 if (recordMetadata != null) {
52 log.info("Topic: {}, Partition: {}, Offset: {}", recordMetadata.topic(), recordMetadata.partition(), recordMetadata.offset());
58 log.info("Fetch {} from topic: {}", fetch, testTopic);
59 List<String> res = handler.fetchFromTopic(testTopic);
60 log.info("Messages from fetch {}: " + res, fetch);