1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. 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
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package org.onap.dmaap.mr.test.clients;
24 import java.io.FileReader;
25 import java.io.FileWriter;
26 import java.io.IOException;
27 import java.util.Properties;
28 import org.json.JSONObject;
29 import org.onap.dmaap.mr.client.MRBatchingPublisher;
30 import org.onap.dmaap.mr.client.MRClientFactory;
31 import org.onap.dmaap.mr.client.response.MRPublisherResponse;
33 *An example of how to use the Java publisher.
37 public class SimpleExamplePublisherWithResponse
39 static FileWriter routeWriter= null;
40 static Properties props=null;
41 static FileReader routeReader=null;
43 public static void main(String []args) throws InterruptedException, Exception{
45 String routeFilePath="src/main/resources/dme2/preferredRoute.txt";
46 String msgCount = args[0];
47 SimpleExamplePublisherWithResponse publisher = new SimpleExamplePublisherWithResponse();
48 File fo= new File(routeFilePath);
50 routeWriter=new FileWriter(new File (routeFilePath));
52 routeReader= new FileReader(new File (routeFilePath));
53 props= new Properties();
55 while (i< Integer.valueOf(msgCount))
57 publisher.publishMessage("src/main/resources/dme2/producer.properties",Integer.valueOf(msgCount));
62 public void publishMessage ( String producerFilePath , int count ) throws IOException, InterruptedException
64 // create our publisher
65 final MRBatchingPublisher pub = MRClientFactory.createBatchingPublisher (producerFilePath,true);
66 // publish some messages
67 final JSONObject msg1 = new JSONObject ();
69 msg1.put ( "Partition:1", "Message:"+count);
70 msg1.put ( "greeting", "Hello .." );
73 pub.send ( "1", msg1.toString());
74 pub.send ( "1", msg1.toString());
76 MRPublisherResponse res= pub.sendBatchWithResponse();
78 System.out.println("Pub response->"+res.toString());