1 package org.onap.policy.utils;
4 import java.util.Properties;
6 import com.att.nsa.mr.client.impl.MRConsumerImpl;
7 import com.att.nsa.mr.test.clients.ProtocolTypeConstants;
9 public interface BusConsumer {
14 * @return list of messages
15 * @throws Exception when error encountered by underlying libraries
17 public Iterable<String> fetch() throws Exception;
20 * close underlying library consumer
27 public static class DmaapConsumerWrapper implements BusConsumer {
32 protected MRConsumerImpl consumer;
37 * @param servers messaging bus hosts
39 * @param apiKey API Key
40 * @param apiSecret API Secret
41 * @param aafLogin AAF Login
42 * @param aafPassword AAF Password
43 * @param consumerGroup Consumer Group
44 * @param consumerInstance Consumer Instance
45 * @param fetchTimeout Fetch Timeout
46 * @param fetchLimit Fetch Limit
48 public DmaapConsumerWrapper(List<String> servers, String topic,
49 String aafLogin, String aafPassword,
50 String consumerGroup, String consumerInstance,
51 int fetchTimeout, int fetchLimit)
54 this.consumer = new MRConsumerImpl(servers, topic,
55 consumerGroup, consumerInstance,
56 fetchTimeout, fetchLimit,
57 null, aafLogin, aafPassword);
59 this.consumer.setUsername(aafLogin);
60 this.consumer.setPassword(aafPassword);
62 this.consumer.setProtocolFlag(ProtocolTypeConstants.AAF_AUTH.getValue());
64 Properties props = new Properties();
65 props.setProperty("Protocol", "http");
66 this.consumer.setProps(props);
67 this.consumer.setHost(servers.get(0) + ":3904");
73 public Iterable<String> fetch() throws Exception {
74 return this.consumer.fetch();
81 this.consumer.close();
85 public String toString() {
86 StringBuilder builder = new StringBuilder();
88 append("DmaapConsumerWrapper [").
89 append("consumer.getAuthDate()=").append(consumer.getAuthDate()).
90 append(", consumer.getAuthKey()=").append(consumer.getAuthKey()).
91 append(", consumer.getHost()=").append(consumer.getHost()).
92 append(", consumer.getProtocolFlag()=").append(consumer.getProtocolFlag()).
93 append(", consumer.getUsername()=").append(consumer.getUsername()).
95 return builder.toString();