1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright © 2021 Orange.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 *******************************************************************************/
24 package org.onap.dmaap.mr.test.clients;
26 import org.onap.dmaap.mr.client.MRClientFactory;
27 import org.onap.dmaap.mr.client.MRConsumer;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import java.util.LinkedList;
33 public class SampleConsumer {
34 private SampleConsumer() {
37 public static void main(String[] args) {
38 final Logger logger = LoggerFactory.getLogger(SampleConsumer.class);
41 logger.info("Sample Consumer Class executing");
42 final String topic = "org.onap.dmaap.mr.testingTopic";
43 final String url = (args.length > 1 ? args[1] : "localhost:8181");
44 final String group = (args.length > 2 ? args[2] : "grp");
46 final String id = (args.length > 3 ? args[3] : "1");
49 long nextReport = 5000;
51 final long startMs = System.currentTimeMillis();
53 final LinkedList<String> urlList = new LinkedList<>();
54 for (String u : url.split(",")) {
58 final MRConsumer cc = MRClientFactory.createConsumer(urlList, topic, group, id, 10 * 1000, 1000, null, "CG0TXc2Aa3v8LfBk", "pj2rhxJWKP23pgy8ahMnjH88");
61 for (String msg : cc.fetch()) {
62 logger.info("" + (++count) + ": " + msg);
65 if (count > nextReport) {
68 final long endMs = System.currentTimeMillis();
69 final long elapsedMs = endMs - startMs;
70 final double elapsedSec = elapsedMs / 1000.0;
71 final double eps = count / elapsedSec;
72 logger.info("Consumed " + count + " in " + elapsedSec + "; " + eps + " eps");
74 logger.info("" + (++count) + ": consumed message");
76 } catch (Exception x) {
77 logger.error(x.getClass().getName() + ": " + x.getMessage());
78 throw new IllegalArgumentException(x);