FINERACT-1724: Removed accidental closing of JMS connection upon startup
This commit is contained in:
committed by
Arnold Gálovics
parent
7d28646c7d
commit
66e4ac6194
+19
-10
@@ -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.core.service.HashingService;
|
||||||
import org.apache.fineract.infrastructure.event.external.exception.AcknowledgementTimeoutException;
|
import org.apache.fineract.infrastructure.event.external.exception.AcknowledgementTimeoutException;
|
||||||
import org.apache.fineract.infrastructure.event.external.producer.ExternalEventProducer;
|
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.InitializingBean;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
@@ -49,7 +50,7 @@ import org.springframework.stereotype.Component;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@ConditionalOnProperty(value = "fineract.events.external.producer.jms.enabled", havingValue = "true")
|
@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")
|
@Qualifier("eventDestination")
|
||||||
private final Destination destination;
|
private final Destination destination;
|
||||||
@@ -67,22 +68,30 @@ public class JMSMultiExternalEventProducer implements ExternalEventProducer, Ini
|
|||||||
|
|
||||||
private final List<MessageProducer> producers = new ArrayList<>();
|
private final List<MessageProducer> producers = new ArrayList<>();
|
||||||
|
|
||||||
|
private Connection connection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
int producerCount = getProducerCount();
|
int producerCount = getProducerCount();
|
||||||
try (Connection connection = connectionFactory.createConnection()) {
|
connection = connectionFactory.createConnection();
|
||||||
for (int i = 0; i < producerCount; i++) {
|
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
|
// It's crucial to create the session within the loop, otherwise the producers won't be handled as
|
||||||
// parallel
|
// parallel
|
||||||
// producers
|
// producers
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
MessageProducer producer = session.createProducer(destination);
|
MessageProducer producer = session.createProducer(destination);
|
||||||
producers.add(producer);
|
producers.add(producer);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
log.info("Initialized JMS multi producer for external events with {} parallel producers", producerCount);
|
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() {
|
private int getProducerCount() {
|
||||||
return fineractProperties.getEvents().getExternal().getProducer().getJms().getProducerCount();
|
return fineractProperties.getEvents().getExternal().getProducer().getJms().getProducerCount();
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -101,7 +101,6 @@ class JMSMultiExternalEventProducerTest {
|
|||||||
verify(session1).createProducer(destination);
|
verify(session1).createProducer(destination);
|
||||||
verify(session2).createProducer(destination);
|
verify(session2).createProducer(destination);
|
||||||
verify(session3).createProducer(destination);
|
verify(session3).createProducer(destination);
|
||||||
verify(connection).close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user