X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-ncmp-service%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fcps%2Fncmp%2Fapi%2Fimpl%2Fevents%2FEventsPublisher.java;h=4c9064852169cb4229e4be7766e91fe737f362ed;hb=ad9b701a00c237ae8e462de76b500c8612866da6;hp=7b28b4cd5fa7da38febf72bde1b21b817644ae3f;hpb=a287fc3286c38a6f472a9262777efc16798f705a;p=cps.git diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/EventsPublisher.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/EventsPublisher.java index 7b28b4cd5..4c9064852 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/EventsPublisher.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/EventsPublisher.java @@ -43,22 +43,38 @@ import org.springframework.util.concurrent.ListenableFutureCallback; @RequiredArgsConstructor public class EventsPublisher { - /** Once all cps events will be modified to cloud compliant, will remove legacyKafkaEventTemplate with - it's java configuration file KafkaTemplateConfig. **/ + /** + * KafaTemplate for legacy (non-cloud) events. + * + * @deprecated Cloud events should be used. Will address soon as part of https://jira.onap.org/browse/CPS-1717 + */ @Deprecated(forRemoval = true) private final KafkaTemplate legacyKafkaEventTemplate; private final KafkaTemplate cloudEventKafkaTemplate; + /** + * Generic CloudEvent publisher. + * + * @param topicName valid topic name + * @param eventKey message key + * @param event message payload + */ + public void publishCloudEvent(final String topicName, final String eventKey, final CloudEvent event) { + final ListenableFuture> eventFuture + = cloudEventKafkaTemplate.send(topicName, eventKey, event); + eventFuture.addCallback(handleCallback(topicName)); + } + /** * Generic Event publisher. * * @param topicName valid topic name * @param eventKey message key * @param event message payload - * @deprecated This method is not needed anymore since the use of headers will be in place. + * @deprecated Cloud events should be used. Will address soon as part of https://jira.onap.org/browse/CPS-1717 */ - @Deprecated + @Deprecated(forRemoval = true) public void publishEvent(final String topicName, final String eventKey, final T event) { final ListenableFuture> eventFuture = legacyKafkaEventTemplate.send(topicName, eventKey, event); @@ -95,7 +111,7 @@ public class EventsPublisher { publishEvent(topicName, eventKey, convertToKafkaHeaders(eventHeaders), event); } - private ListenableFutureCallback> handleCallback(final String topicName) { + private ListenableFutureCallback> handleCallback(final String topicName) { return new ListenableFutureCallback<>() { @Override public void onFailure(final Throwable throwable) { @@ -103,7 +119,7 @@ public class EventsPublisher { } @Override - public void onSuccess(final SendResult sendResult) { + public void onSuccess(final SendResult sendResult) { log.debug("Successfully published event to topic : {} , Event : {}", sendResult.getRecordMetadata().topic(), sendResult.getProducerRecord().value()); }