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.apps.uservice.test.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 * @author Liam Fallon (liam.fallon@ericsson.com)
34 public class TestKafkaXMLEventProducer {
36 public static void main(final String[] args) {
37 final Properties props = new Properties();
38 props.put("bootstrap.servers", "localhost:49092");
39 props.put("acks", "all");
40 props.put("retries", 0);
41 props.put("batch.size", 16384);
42 props.put("linger.ms", 1);
43 props.put("buffer.memory", 33554432);
44 props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
45 props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
47 final XMLApexEvent xmlEvent = new XMLApexEvent();
48 xmlEvent.setName("XMLEvent-1");
49 xmlEvent.setVersion("0.0.1");
50 xmlEvent.getData().add(new XMLApexEventData("Data-1", "Data Value -1"));
52 final Producer<String, String> producer = new KafkaProducer<String, String>(props);
53 for (int i = 0; i < 100; i++) {
54 xmlEvent.setName("XMLEvent" + Integer.toString(i));
55 xmlEvent.setVersion("0.0.1");
57 .add(new XMLApexEventData("Data" + Integer.toString(i), "Data Value " + Integer.toString(i)));
59 producer.send(new ProducerRecord<String, String>("apex-in-0", xmlEvent.getName(), xmlEvent.toString()));