2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
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=========================================================
21 package org.onap.policy.apex.testsuites.integration.uservice.adapt.kafka;
23 import java.util.Properties;
25 import org.apache.kafka.clients.producer.KafkaProducer;
26 import org.apache.kafka.clients.producer.Producer;
27 import org.apache.kafka.clients.producer.ProducerRecord;
28 import org.onap.policy.apex.plugins.event.protocol.xml.jaxb.XMLApexEvent;
29 import org.onap.policy.apex.plugins.event.protocol.xml.jaxb.XMLApexEventData;
32 * The Class TestKafkaXmlEventProducer.
34 * @author Liam Fallon (liam.fallon@ericsson.com)
36 public class TestKafkaXmlEventProducer {
41 * @param args the arguments
43 public static void main(final String[] args) {
44 final Properties props = new Properties();
45 props.put("bootstrap.servers", "localhost:49092");
46 props.put("acks", "all");
47 props.put("retries", 0);
48 props.put("batch.size", 16384);
49 props.put("linger.ms", 1);
50 props.put("buffer.memory", 33554432);
51 props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
52 props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
54 final XMLApexEvent xmlEvent = new XMLApexEvent();
55 xmlEvent.setName("XMLEvent-1");
56 xmlEvent.setVersion("0.0.1");
57 xmlEvent.getData().add(new XMLApexEventData("Data-1", "Data Value -1"));
59 final Producer<String, String> producer = new KafkaProducer<String, String>(props);
60 for (int i = 0; i < 100; i++) {
61 xmlEvent.setName("XMLEvent" + Integer.toString(i));
62 xmlEvent.setVersion("0.0.1");
64 .add(new XMLApexEventData("Data" + Integer.toString(i), "Data Value " + Integer.toString(i)));
66 producer.send(new ProducerRecord<String, String>("apex-in-0", xmlEvent.getName(), xmlEvent.toString()));