This is an automated email from the ASF dual-hosted git repository.

arnold pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 66e4ac619 FINERACT-1724: Removed accidental closing of JMS connection 
upon startup
66e4ac619 is described below

commit 66e4ac61945542779c5c2136a5fca03b8555964e
Author: Arnold Galovics <[email protected]>
AuthorDate: Thu Jan 19 12:08:38 2023 +0100

    FINERACT-1724: Removed accidental closing of JMS connection upon startup
---
 .../jms/JMSMultiExternalEventProducer.java         | 29 ++++++++++++++--------
 .../jms/JMSMultiExternalEventProducerTest.java     |  1 -
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/producer/jms/JMSMultiExternalEventProducer.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/producer/jms/JMSMultiExternalEventProducer.java
index e063e44f4..794c45cc3 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/producer/jms/JMSMultiExternalEventProducer.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/producer/jms/JMSMultiExternalEventProducer.java
@@ -39,6 +39,7 @@ import 
org.apache.fineract.infrastructure.core.messaging.jms.MessageFactory;
 import org.apache.fineract.infrastructure.core.service.HashingService;
 import 
org.apache.fineract.infrastructure.event.external.exception.AcknowledgementTimeoutException;
 import 
org.apache.fineract.infrastructure.event.external.producer.ExternalEventProducer;
+import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -49,7 +50,7 @@ import org.springframework.stereotype.Component;
 @Slf4j
 @RequiredArgsConstructor
 @ConditionalOnProperty(value = 
"fineract.events.external.producer.jms.enabled", havingValue = "true")
-public class JMSMultiExternalEventProducer implements ExternalEventProducer, 
InitializingBean {
+public class JMSMultiExternalEventProducer implements ExternalEventProducer, 
InitializingBean, DisposableBean {
 
     @Qualifier("eventDestination")
     private final Destination destination;
@@ -67,22 +68,30 @@ public class JMSMultiExternalEventProducer implements 
ExternalEventProducer, Ini
 
     private final List<MessageProducer> producers = new ArrayList<>();
 
+    private Connection connection;
+
     @Override
     public void afterPropertiesSet() throws Exception {
         int producerCount = getProducerCount();
-        try (Connection connection = connectionFactory.createConnection()) {
-            for (int i = 0; i < producerCount; i++) {
-                // It's crucial to create the session within the loop, 
otherwise the producers won't be handled as
-                // parallel
-                // producers
-                Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
-                MessageProducer producer = session.createProducer(destination);
-                producers.add(producer);
-            }
+        connection = connectionFactory.createConnection();
+        for (int i = 0; i < producerCount; i++) {
+            // It's crucial to create the session within the loop, otherwise 
the producers won't be handled as
+            // parallel
+            // producers
+            Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
+            MessageProducer producer = session.createProducer(destination);
+            producers.add(producer);
         }
         log.info("Initialized JMS multi producer for external events with {} 
parallel producers", producerCount);
     }
 
+    @Override
+    public void destroy() throws Exception {
+        if (connection != null) {
+            connection.close();
+        }
+    }
+
     private int getProducerCount() {
         return 
fineractProperties.getEvents().getExternal().getProducer().getJms().getProducerCount();
     }
diff --git 
a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/producer/jms/JMSMultiExternalEventProducerTest.java
 
b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/producer/jms/JMSMultiExternalEventProducerTest.java
index 503717ed8..2f28dca2a 100644
--- 
a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/producer/jms/JMSMultiExternalEventProducerTest.java
+++ 
b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/producer/jms/JMSMultiExternalEventProducerTest.java
@@ -101,7 +101,6 @@ class JMSMultiExternalEventProducerTest {
         verify(session1).createProducer(destination);
         verify(session2).createProducer(destination);
         verify(session3).createProducer(destination);
-        verify(connection).close();
     }
 
     @Test

Reply via email to