bdd15d4895d20c1a29cfbdc9db68dff97e0ee4a3
[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 import java.util.List;
36
37 public class SimpleExampleConsumer {
38
39         private static final Logger logger = LoggerFactory.getLogger(SimpleExampleConsumer.class);
40
41     private SimpleExampleConsumer() {
42     }
43
44         public static void main(String[] args) {
45
46                 long count = 0;
47                 long nextReport = 5000;
48                 String key;
49
50                 final long startMs = System.currentTimeMillis();
51
52                 try {
53
54                         final MRConsumer cc = MRClientFactory.createConsumer("D:\\SG\\consumer.properties");
55                         while (true) {
56                                 for (String msg : cc.fetch()) {
57                                         logger.debug("Message Received: " + msg);
58                                 }
59                                 // Header for DME2 Call.
60                                 MultivaluedMap<String, Object> headersMap = MRClientFactory.HTTPHeadersMap;
61                                 for (MultivaluedMap.Entry<String,List<Object>> entry: headersMap.entrySet()) {
62                                     key = entry.getKey();
63                                     logger.debug("Header Key " + key);
64                                     logger.debug("Header Value " + headersMap.get(key));
65                                 }
66                                 // Header for HTTP Call.
67                                 
68                                  Map<String, String> dme2headersMap=MRClientFactory.DME2HeadersMap;
69                                  for(Map.Entry<String,String> entry: dme2headersMap.entrySet()) {
70                                      key = entry.getKey();
71                                      logger.debug("Header Key " + key);
72                                      logger.debug("Header Value " + dme2headersMap.get(key));
73                                  }
74                                  
75                                 if (count > nextReport) {
76                                         nextReport += 5000;
77
78                                         final long endMs = System.currentTimeMillis();
79                                         final long elapsedMs = endMs - startMs;
80                                         final double elapsedSec = elapsedMs / 1000.0;
81                                         final double eps = count / elapsedSec;
82                                         logger.error("Consumed " + count + " in " + elapsedSec + "; " + eps + " eps");
83                                 }
84                         }
85                 } catch (Exception x) {
86                     logger.error(x.getClass().getName() + ": " + x.getMessage());
87                 }
88         }
89 }