2 * Copyright 2017 ZTE Corporation.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.holmes.common.dmaap;
\r
19 import java.util.Collections;
\r
20 import java.util.List;
\r
21 import javax.ws.rs.client.Client;
\r
22 import javax.ws.rs.client.ClientBuilder;
\r
23 import javax.ws.rs.client.WebTarget;
\r
24 import javax.ws.rs.core.Response;
\r
25 import lombok.Getter;
\r
26 import lombok.Setter;
\r
27 import org.glassfish.jersey.client.ClientConfig;
\r
28 import org.onap.holmes.common.dmaap.entity.VesAlarm;
\r
29 import org.onap.holmes.common.exception.CorrelationException;
\r
33 public class Subscriber {
\r
35 * The number of milliseconds to wait for messages if none are immediately
\r
36 * available. This should normally be used, and set at 15000 or higher.
\r
38 private int timeout = 15000;
\r
41 * The maximum number of messages to return
\r
43 private int limit = 100;
\r
45 private boolean secure;
\r
46 private String topic;
\r
48 private String consumerGroup = "g0";
\r
49 private String consumer = "u1";
\r
50 private String authInfo;
\r
51 private String authExpDate;
\r
53 List<VesAlarm> subscribe() throws CorrelationException {
\r
54 Client client = ClientBuilder.newClient(new ClientConfig());
\r
55 WebTarget webTarget = client.target(url);
\r
56 Response response = webTarget.path(topic).path(consumerGroup).path(consumer).request().get();
\r
59 return extractAlarms(response);
\r
61 catch (Exception e) {
\r
62 throw new CorrelationException("Failed to convert the response data to VES alarms.", e);
\r
66 private List<VesAlarm> extractAlarms(Response response) {
\r
67 return Collections.emptyList();
\r