Merge "Fix for Sonar Major issues"
[dmaap/messagerouter/dmaapclient.git] / src / main / java / com / att / nsa / mr / dme / client / SimpleExampleConsumer.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
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
11  *  
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=========================================================
18  *
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *  
21  *******************************************************************************/
22
23 package com.att.nsa.mr.dme.client;
24
25 import java.util.Map;
26
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import javax.ws.rs.core.MultivaluedMap;
31
32 import com.att.nsa.mr.client.MRClientFactory;
33 import com.att.nsa.mr.client.MRConsumer;
34
35 public class SimpleExampleConsumer {
36
37         private static final Logger logger = LoggerFactory.getLogger(SimpleExampleConsumer.class);
38
39         public static void main(String[] args) {
40
41                 long count = 0;
42                 long nextReport = 5000;
43
44                 final long startMs = System.currentTimeMillis();
45
46                 try {
47
48                         final MRConsumer cc = MRClientFactory.createConsumer("D:\\SG\\consumer.properties");
49                         while (true) {
50                                 for (String msg : cc.fetch()) {
51
52                                         System.out.println("Message Received: " + msg);
53                                 }
54                                 // Header for DME2 Call.
55                                 MultivaluedMap<String, Object> headersMap = MRClientFactory.HTTPHeadersMap;
56                                 for (String key : headersMap.keySet()) {
57                                         System.out.println("Header Key " + key);
58                                         System.out.println("Header Value " + headersMap.get(key));
59                                 }
60                                 // Header for HTTP Call.
61                                 
62                                  Map<String, String>
63                                  dme2headersMap=MRClientFactory.DME2HeadersMap; for(String key
64                                   : dme2headersMap.keySet()) { System.out.println("Header Key "
65                                 + key); System.out.println("Header Value " +
66                                   dme2headersMap.get(key)); }
67                                  
68                                 if (count > nextReport) {
69                                         nextReport += 5000;
70
71                                         final long endMs = System.currentTimeMillis();
72                                         final long elapsedMs = endMs - startMs;
73                                         final double elapsedSec = elapsedMs / 1000.0;
74                                         final double eps = count / elapsedSec;
75                                         System.out.println("Consumed " + count + " in " + elapsedSec + "; " + eps + " eps");
76                                 }
77                         }
78                 } catch (Exception x) {
79                         System.err.println(x.getClass().getName() + ": " + x.getMessage());
80                     logger.error("exception: ", x);
81                 }
82         }
83 }