2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
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
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.client.impl.protocol;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
30 import java.io.IOException;
31 import java.security.GeneralSecurityException;
34 class UEBMessagingService implements MessagingService {
36 private Consumer consumer;
37 private Producer producer;
39 private final String DEFAULT_READ_TIMEOUT_MS = "60000";
40 private final String DEFAULT_READ_LIMIT = "1000";
42 private int readLimit;
44 private final EELFLogger LOG = EELFManager.getInstance().getLogger(UEBMessagingService.class);
46 @SuppressWarnings("Since15")
47 public void init(Properties props) throws IOException, GeneralSecurityException, NoSuchFieldException, IllegalAccessException {
50 String readTopic = props.getProperty(UEBPropertiesKeys.TOPIC_READ);
51 String writeTopic = props.getProperty(UEBPropertiesKeys.TOPIC_WRITE);
52 String apiKey = props.getProperty(UEBPropertiesKeys.AUTH_USER);
53 String apiSecret = props.getProperty(UEBPropertiesKeys.AUTH_SECRET);
54 String readTimeoutString = props.getProperty(UEBPropertiesKeys.TOPIC_READ_TIMEOUT, DEFAULT_READ_TIMEOUT_MS);
55 Integer readTimeout = Integer.parseInt(readTimeoutString);
56 String readLimitString = props.getProperty(UEBPropertiesKeys.READ_LIMIT, DEFAULT_READ_LIMIT);
57 readLimit = Integer.parseInt(readLimitString);
59 Collection<String> pool = new HashSet<String>();
60 String hostNames = props.getProperty(UEBPropertiesKeys.HOSTS);
61 if (hostNames != null && !hostNames.isEmpty()) {
62 for (String name : hostNames.split(",")) {
67 //generate consumer id and group - same value for both
68 String consumerName = UUID.randomUUID().toString();
69 String consumerID = consumerName;
71 //create consumer and producer
72 consumer = new ConsumerImpl(pool, readTopic, consumerName, consumerID, readTimeout, apiKey, apiSecret);
73 producer = new ProducerImpl(pool, writeTopic, apiKey, apiSecret);
75 //initial consumer registration
77 consumer.registerForRead();
79 LOG.error("Message consumer failed to register client "+consumerID);
84 public void send(String partition, String body) throws IOException {
85 producer.post(partition, body);
88 public List<String> fetch() throws IOException {
89 return consumer.fetch(readLimit);
92 public List<String> fetch(int limit) throws IOException {
93 return consumer.fetch(limit);