From 85c21e1d85c545717affd3f18cd8e9fe6dc14562 Mon Sep 17 00:00:00 2001 From: "sunil.unnava" Date: Tue, 23 Jan 2018 15:26:15 -0500 Subject: Changes to the DMaap Client Added new API to the DMaapClient Issue-ID: DMAAP-214 Change-Id: I4de2da7ca42ad1b5925a2df9d26672875dd15b10 Signed-off-by: sunil.unnava --- .../nsa/mr/test/clients/ProtocolTypeConstants.java | 8 +-- .../nsa/mr/test/clients/SimpleExampleConsumer.java | 71 ++++++++++------------ 2 files changed, 36 insertions(+), 43 deletions(-) (limited to 'src/main/java/com/att/nsa/mr/test/clients') diff --git a/src/main/java/com/att/nsa/mr/test/clients/ProtocolTypeConstants.java b/src/main/java/com/att/nsa/mr/test/clients/ProtocolTypeConstants.java index 6e86d47..a4a176e 100644 --- a/src/main/java/com/att/nsa/mr/test/clients/ProtocolTypeConstants.java +++ b/src/main/java/com/att/nsa/mr/test/clients/ProtocolTypeConstants.java @@ -29,11 +29,9 @@ package com.att.nsa.mr.test.clients; * */ public enum ProtocolTypeConstants { - - DME2("DME2"), - AAF_AUTH("HTTPAAF"), - AUTH_KEY("HTTPAUTH"); - + + DME2("DME2"), AAF_AUTH("HTTPAAF"), AUTH_KEY("HTTPAUTH"), HTTPNOAUTH("HTTPNOAUTH"); + private String value; private ProtocolTypeConstants(String value) { diff --git a/src/main/java/com/att/nsa/mr/test/clients/SimpleExampleConsumer.java b/src/main/java/com/att/nsa/mr/test/clients/SimpleExampleConsumer.java index 5ae36d2..0e3ee5a 100644 --- a/src/main/java/com/att/nsa/mr/test/clients/SimpleExampleConsumer.java +++ b/src/main/java/com/att/nsa/mr/test/clients/SimpleExampleConsumer.java @@ -33,57 +33,52 @@ import org.slf4j.LoggerFactory; import com.att.nsa.mr.client.MRClientFactory; import com.att.nsa.mr.client.MRConsumer; -public class SimpleExampleConsumer -{ +public class SimpleExampleConsumer { - static FileWriter routeWriter= null; - static Properties props=null; - static FileReader routeReader=null; - public static void main ( String[] args ) - { + static FileWriter routeWriter = null; + static Properties props = null; + static FileReader routeReader = null; + + public static void main(String[] args) { final Logger LOG = LoggerFactory.getLogger(SimpleExampleConsumer.class); - + long count = 0; long nextReport = 5000; - final long startMs = System.currentTimeMillis (); - - try - { - String routeFilePath="/src/main/resources/dme2/preferredRoute.txt"; - - - File fo= new File(routeFilePath); - if(!fo.exists()){ - routeWriter=new FileWriter(new File (routeFilePath)); - } - routeReader= new FileReader(new File (routeFilePath)); - props= new Properties(); - final MRConsumer cc = MRClientFactory.createConsumer ( "/src/main/resources/dme2/consumer.properties" ); - while ( true ) - { - for ( String msg : cc.fetch () ) - { - //System.out.println ( "" + (++count) + ": " + msg ); + final long startMs = System.currentTimeMillis(); + + try { + String routeFilePath = "/src/main/resources/dme2/preferredRoute.txt"; + + File fo = new File(routeFilePath); + if (!fo.exists()) { + routeWriter = new FileWriter(new File(routeFilePath)); + } + routeReader = new FileReader(new File(routeFilePath)); + props = new Properties(); + final MRConsumer cc = MRClientFactory.createConsumer("/src/main/resources/dme2/consumer.properties"); + int i = 0; + while (i < 10) { + Thread.sleep(2); + i++; + for (String msg : cc.fetch()) { + // System.out.println ( "" + (++count) + ": " + msg ); System.out.println(msg); } - - if ( count > nextReport ) - { + + if (count > nextReport) { nextReport += 5000; - - final long endMs = System.currentTimeMillis (); + + final long endMs = System.currentTimeMillis(); final long elapsedMs = endMs - startMs; final double elapsedSec = elapsedMs / 1000.0; final double eps = count / elapsedSec; - System.out.println ( "Consumed " + count + " in " + elapsedSec + "; " + eps + " eps" ); + System.out.println("Consumed " + count + " in " + elapsedSec + "; " + eps + " eps"); } } - } - catch ( Exception x ) - { - System.err.println ( x.getClass().getName () + ": " + x.getMessage () ); - LOG.error("exception: ", x); + } catch (Exception x) { + System.err.println(x.getClass().getName() + ": " + x.getMessage()); + LOG.error("exception: ", x); } } } -- cgit 1.2.3-korg