Revert "Migrate CPS to Spring-boot 3.0"
[cps.git] / cps-ncmp-service / src / main / java / org / onap / cps / ncmp / api / impl / events / EventsPublisher.java
index 7b28b4c..4c90648 100644 (file)
@@ -43,22 +43,38 @@ import org.springframework.util.concurrent.ListenableFutureCallback;
 @RequiredArgsConstructor
 public class EventsPublisher<T> {
 
-    /** 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<String, T> legacyKafkaEventTemplate;
 
     private final KafkaTemplate<String, CloudEvent> 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<SendResult<String, CloudEvent>> 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<SendResult<String, T>> eventFuture
                 = legacyKafkaEventTemplate.send(topicName, eventKey, event);
@@ -95,7 +111,7 @@ public class EventsPublisher<T> {
         publishEvent(topicName, eventKey, convertToKafkaHeaders(eventHeaders), event);
     }
 
-    private ListenableFutureCallback<SendResult<String, T>> handleCallback(final String topicName) {
+    private ListenableFutureCallback<SendResult<String, ?>> handleCallback(final String topicName) {
         return new ListenableFutureCallback<>() {
             @Override
             public void onFailure(final Throwable throwable) {
@@ -103,7 +119,7 @@ public class EventsPublisher<T> {
             }
 
             @Override
-            public void onSuccess(final SendResult<String, T> sendResult) {
+            public void onSuccess(final SendResult<String, ?> sendResult) {
                 log.debug("Successfully published event to topic : {} , Event : {}",
                         sendResult.getRecordMetadata().topic(), sendResult.getProducerRecord().value());
             }