2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA 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
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.dcaegen2.collectors.datafile.tasks;
23 import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration;
24 import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
25 import org.onap.dcaegen2.collectors.datafile.configuration.Config;
26 import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapNotFoundException;
27 import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
28 import org.onap.dcaegen2.collectors.datafile.service.producer.DMaaPProducerReactiveHttpClient;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Component;
33 import reactor.core.publisher.Mono;
36 * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
39 public class DmaapPublisherTaskImpl extends DmaapPublisherTask {
41 private final Logger logger = LoggerFactory.getLogger(this.getClass());
42 private final Config datafileAppConfig;
43 private DMaaPProducerReactiveHttpClient dmaapProducerReactiveHttpClient;
46 public DmaapPublisherTaskImpl(AppConfig datafileAppConfig) {
47 this.datafileAppConfig = datafileAppConfig;
51 Mono<String> publish(Mono<ConsumerDmaapModel> consumerDmaapModel) {
52 logger.info("Publishing on DMaaP topic {} object {}", resolveConfiguration().dmaapTopicName(),
54 return dmaapProducerReactiveHttpClient.getDMaaPProducerResponse(consumerDmaapModel);
58 public Mono<String> execute(Mono<ConsumerDmaapModel> consumerDmaapModel) throws DmaapNotFoundException {
59 if (consumerDmaapModel == null) {
60 throw new DmaapNotFoundException("Invoked null object to DMaaP task");
62 dmaapProducerReactiveHttpClient = resolveClient();
63 logger.trace("Method called with arg {}", consumerDmaapModel);
64 return publish(consumerDmaapModel);
68 protected DmaapPublisherConfiguration resolveConfiguration() {
69 return datafileAppConfig.getDmaapPublisherConfiguration();
73 DMaaPProducerReactiveHttpClient resolveClient() {
74 return dmaapProducerReactiveHttpClient == null
75 ? new DMaaPProducerReactiveHttpClient(resolveConfiguration()).createDMaaPWebClient(buildWebClient())
76 : dmaapProducerReactiveHttpClient;