Swallow kafkaException 58/131358/2
authormpriyank <priyank.maheshwari@est.tech>
Mon, 3 Oct 2022 11:26:10 +0000 (12:26 +0100)
committermpriyank <priyank.maheshwari@est.tech>
Mon, 3 Oct 2022 11:44:38 +0000 (12:44 +0100)
- swallow the kafka exception if we are unable to send the kafka message
  due to any reason.
- updated release notes as well

Issue-ID: CPS-1294
Change-Id: Iaa8ae5b0bc289d819a46b4a95a1382f4ecee66aa
Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsService.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsServiceSpec.groovy
docs/release-notes.rst

index 762b21e..d6857d3 100644 (file)
@@ -24,6 +24,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.onap.ncmp.cmhandle.event.lcm.LcmEvent;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.kafka.KafkaException;
 import org.springframework.stereotype.Service;
 
 /**
@@ -51,7 +52,11 @@ public class LcmEventsService {
      */
     public void publishLcmEvent(final String cmHandleId, final LcmEvent lcmEvent) {
         if (notificationsEnabled) {
-            lcmEventsPublisher.publishEvent(topicName, cmHandleId, lcmEvent);
+            try {
+                lcmEventsPublisher.publishEvent(topicName, cmHandleId, lcmEvent);
+            } catch (final KafkaException e) {
+                log.error("Unable to publish message to topic : {} and cause : {}", topicName, e.getMessage());
+            }
         } else {
             log.debug("Notifications disabled.");
         }
index 1eae357..ef399e1 100644 (file)
@@ -21,6 +21,7 @@
 package org.onap.cps.ncmp.api.impl.event.lcm
 
 import org.onap.ncmp.cmhandle.event.lcm.LcmEvent
+import org.springframework.kafka.KafkaException
 import spock.lang.Specification
 
 class LcmEventsServiceSpec extends Specification {
@@ -45,4 +46,17 @@ class LcmEventsServiceSpec extends Specification {
             'disabled' | false                || 0
     }
 
+    def 'Unable to send message'(){
+        given: 'a cm handle id and Lcm Event and notification enabled'
+            def cmHandleId = 'test-cm-handle-id'
+            def lcmEvent = new LcmEvent(eventId: UUID.randomUUID().toString(), eventCorrelationId: cmHandleId)
+            objectUnderTest.notificationsEnabled = true
+        when: 'publisher set to throw an exception'
+            mockLcmEventsPublisher.publishEvent(*_) >> { throw new KafkaException('publishing failed')}
+        and: 'an event is publised'
+            objectUnderTest.publishLcmEvent(cmHandleId, lcmEvent)
+        then: 'the exception is just logged and not bubbled up'
+            noExceptionThrown()
+    }
+
 }
index 69a1a35..43ee654 100755 (executable)
@@ -38,7 +38,7 @@ Release Data
 
 Bug Fixes
 ---------
-   - None
+   - `CPS-1294 <https://jira.onap.org/browse/CPS-1294>`_  Kafka communication fault caused cmHandle registration error
 
 Version: 3.1.3
 ==============