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.messagerouter.dmaapclient.nsa.mr.test.clients;
 
  24 import java.io.FileReader;
 
  25 import java.io.FileWriter;
 
  26 import java.io.IOException;
 
  27 import java.util.List;
 
  28 import java.util.Properties;
 
  29 import java.util.concurrent.TimeUnit;
 
  30 import org.json.JSONObject;
 
  31 import org.onap.dmaap.messagerouter.dmaapclient.nsa.mr.client.MRBatchingPublisher;
 
  32 import org.onap.dmaap.messagerouter.dmaapclient.nsa.mr.client.MRClientFactory;
 
  33 import org.onap.dmaap.messagerouter.dmaapclient.nsa.mr.client.response.MRPublisherResponse;
 
  35          *An example of how to use the Java publisher. 
 
  39         public class SimpleExamplePublisherWithResponse
 
  41                 static FileWriter routeWriter= null;
 
  42                 static Properties props=null;   
 
  43                 static FileReader routeReader=null;
 
  45                 public static void main(String []args) throws InterruptedException, Exception{
 
  47                         String routeFilePath="src/main/resources/dme2/preferredRoute.txt";
 
  48                         String msgCount = args[0];
 
  49                         SimpleExamplePublisherWithResponse publisher = new SimpleExamplePublisherWithResponse();
 
  50                         File fo= new File(routeFilePath);
 
  52                                         routeWriter=new FileWriter(new File (routeFilePath));
 
  54                         routeReader= new FileReader(new File (routeFilePath));
 
  55                         props= new Properties();
 
  57                         while (i< Integer.valueOf(msgCount))
 
  59                                 publisher.publishMessage("src/main/resources/dme2/producer.properties",Integer.valueOf(msgCount));
 
  64                 public void publishMessage ( String producerFilePath , int count ) throws IOException, InterruptedException, Exception
 
  66                         // create our publisher
 
  67                         final MRBatchingPublisher pub = MRClientFactory.createBatchingPublisher (producerFilePath,true);        
 
  68                         // publish some messages
 
  69                         final JSONObject msg1 = new JSONObject ();
 
  71                         msg1.put ( "Partition:1", "Message:"+count);
 
  72                         msg1.put ( "greeting", "Hello  .." );
 
  75                         pub.send ( "1", msg1.toString());
 
  76                         pub.send ( "1", msg1.toString());
 
  78                         MRPublisherResponse res= pub.sendBatchWithResponse();
 
  80                         System.out.println("Pub response->"+res.toString());