FINERACT-1724: Added the possibility to use username and password for JMS for remote jobs + the ability to disable remote jobs completely for non-batch instances
This commit is contained in:
committed by
Arnold Gálovics
parent
8e597e46f7
commit
61ca7bb0e0
+34
-25
@@ -18,41 +18,50 @@
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.core.condition;
|
||||
|
||||
import java.util.Optional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Condition;
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
import org.apache.fineract.infrastructure.core.config.FineractProperties;
|
||||
|
||||
@Slf4j
|
||||
public class FineractRemoteJobMessageHandlerCondition implements Condition {
|
||||
public class FineractRemoteJobMessageHandlerCondition extends PropertiesCondition {
|
||||
|
||||
@Override
|
||||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||
boolean isSpringEventsEnabled = Optional
|
||||
.ofNullable(
|
||||
context.getEnvironment().getProperty("fineract.remote-job-message-handler.spring-events.enabled", Boolean.class))
|
||||
.orElse(true);
|
||||
boolean isJmsEnabled = Optional
|
||||
.ofNullable(context.getEnvironment().getProperty("fineract.remote-job-message-handler.jms.enabled", Boolean.class))
|
||||
.orElse(true);
|
||||
boolean isBatchManagerModeEnabled = Optional
|
||||
.ofNullable(context.getEnvironment().getProperty("fineract.mode.batch-manager-enabled", Boolean.class)).orElse(true);
|
||||
boolean isBatchWorkerModeEnabled = Optional
|
||||
.ofNullable(context.getEnvironment().getProperty("fineract.mode.batch-worker-enabled", Boolean.class)).orElse(true);
|
||||
// TODO extend this expression with other message handlers in the future
|
||||
protected boolean matches(FineractProperties properties) {
|
||||
boolean isSpringEventsEnabled = properties.getRemoteJobMessageHandler().getSpringEvents().isEnabled();
|
||||
|
||||
boolean conditionFails = false;
|
||||
boolean onlyOneMessageHandlerEnabled = isSpringEventsEnabled ^ isJmsEnabled;
|
||||
if (!onlyOneMessageHandlerEnabled) {
|
||||
conditionFails = true;
|
||||
log.error("For remote partitioning jobs exactly one Message Handler must be enabled.");
|
||||
}
|
||||
if (isSpringEventsEnabled) {
|
||||
if (!(isBatchManagerModeEnabled && isBatchWorkerModeEnabled)) {
|
||||
if (isAnyMessageHandlerConfigured(properties) && isBatchInstance(properties)) {
|
||||
if (!isOnlyOneMessageHandlerEnabled(properties)) {
|
||||
conditionFails = true;
|
||||
log.error("For remote partitioning jobs exactly one Message Handler must be enabled.");
|
||||
} else if (isSpringEventsEnabled && !isBatchManagerAndWorkerTogether(properties)) {
|
||||
conditionFails = true;
|
||||
log.error("If Spring Event Message Handler is enabled, the instance must be Batch Manager and Batch Worker too.");
|
||||
}
|
||||
}
|
||||
return conditionFails;
|
||||
}
|
||||
|
||||
private boolean isOnlyOneMessageHandlerEnabled(FineractProperties properties) {
|
||||
boolean isSpringEventsEnabled = properties.getRemoteJobMessageHandler().getSpringEvents().isEnabled();
|
||||
boolean isJmsEnabled = properties.getRemoteJobMessageHandler().getJms().isEnabled();
|
||||
return isSpringEventsEnabled ^ isJmsEnabled;
|
||||
}
|
||||
|
||||
private boolean isAnyMessageHandlerConfigured(FineractProperties properties) {
|
||||
boolean isSpringEventsEnabled = properties.getRemoteJobMessageHandler().getSpringEvents().isEnabled();
|
||||
boolean isJmsEnabled = properties.getRemoteJobMessageHandler().getJms().isEnabled();
|
||||
return isSpringEventsEnabled || isJmsEnabled;
|
||||
}
|
||||
|
||||
private boolean isBatchInstance(FineractProperties properties) {
|
||||
boolean isBatchManagerModeEnabled = properties.getMode().isBatchManagerEnabled();
|
||||
boolean isBatchWorkerModeEnabled = properties.getMode().isBatchWorkerEnabled();
|
||||
return isBatchManagerModeEnabled || isBatchWorkerModeEnabled;
|
||||
}
|
||||
|
||||
private boolean isBatchManagerAndWorkerTogether(FineractProperties properties) {
|
||||
boolean isBatchManagerModeEnabled = properties.getMode().isBatchManagerEnabled();
|
||||
boolean isBatchWorkerModeEnabled = properties.getMode().isBatchWorkerEnabled();
|
||||
return isBatchManagerModeEnabled && isBatchWorkerModeEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -125,6 +125,12 @@ public class FineractProperties {
|
||||
private boolean enabled;
|
||||
private String requestQueueName;
|
||||
private String brokerUrl;
|
||||
private String brokerUsername;
|
||||
private String brokerPassword;
|
||||
|
||||
public boolean isBrokerPasswordProtected() {
|
||||
return StringUtils.isNotBlank(brokerUsername) || StringUtils.isNotBlank(brokerPassword);
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
||||
+5
@@ -37,6 +37,11 @@ public class JmsBrokerConfiguration {
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
|
||||
connectionFactory.setBrokerURL(fineractProperties.getRemoteJobMessageHandler().getJms().getBrokerUrl());
|
||||
connectionFactory.setTrustAllPackages(true);
|
||||
FineractProperties.FineractRemoteJobMessageHandlerJmsProperties jmsProps = fineractProperties.getRemoteJobMessageHandler().getJms();
|
||||
if (jmsProps.isBrokerPasswordProtected()) {
|
||||
connectionFactory.setUserName(jmsProps.getBrokerUsername());
|
||||
connectionFactory.setPassword(jmsProps.getBrokerPassword());
|
||||
}
|
||||
return connectionFactory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ fineract.remote-job-message-handler.spring-events.enabled=${FINERACT_REMOTE_JOB_
|
||||
fineract.remote-job-message-handler.jms.enabled=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_JMS_ENABLED:false}
|
||||
fineract.remote-job-message-handler.jms.request-queue-name=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_JMS_QUEUE_NAME:JMS-request-queue}
|
||||
fineract.remote-job-message-handler.jms.broker-url=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_JMS_BROKER_URL:tcp://127.0.0.1:61616}
|
||||
fineract.remote-job-message-handler.jms.broker-username=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_JMS_BROKER_USERNAME:}
|
||||
fineract.remote-job-message-handler.jms.broker-password=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_JMS_BROKER_PASSWORD:}
|
||||
|
||||
fineract.events.external.enabled=${FINERACT_EXTERNAL_EVENTS_ENABLED:false}
|
||||
fineract.events.external.producer.read-batch-size=${FINERACT_EXTERNAL_EVENTS_PRODUCER_READ_BATCH_SIZE:1000}
|
||||
|
||||
Reference in New Issue
Block a user