Disable receiving events for batch-only instances

This commit is contained in:
Jose Alberto Hernandez
2022-06-14 09:47:44 +02:00
committed by Arnold Gálovics
parent 79375a8b91
commit a38fc32315
7 changed files with 236 additions and 26 deletions
@@ -0,0 +1,43 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.core.config;
import java.util.Optional;
import org.apache.fineract.infrastructure.instancemode.api.FineractInstanceModeConstants;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
public class EnableFineractEventListenerCondition implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
boolean isReadModeEnabled = Optional.ofNullable(
context.getEnvironment().getProperty(FineractInstanceModeConstants.FINERACT_MODE_READ_ENABLE_PROPERTY, Boolean.class))
.orElse(true);
boolean isWriteModeEnabled = Optional.ofNullable(
context.getEnvironment().getProperty(FineractInstanceModeConstants.FINERACT_MODE_WRITE_ENABLE_PROPERTY, Boolean.class))
.orElse(true);
boolean isBatchModeEnabled = Optional.ofNullable(
context.getEnvironment().getProperty(FineractInstanceModeConstants.FINERACT_MODE_BATCH_ENABLE_PROPERTY, Boolean.class))
.orElse(true);
return (isReadModeEnabled && isBatchModeEnabled && isWriteModeEnabled) // All mode
|| (!isReadModeEnabled && !isBatchModeEnabled && isWriteModeEnabled); // Write mode
}
}
@@ -19,6 +19,7 @@
package org.apache.fineract.infrastructure.core.config;
import java.util.Optional;
import org.apache.fineract.infrastructure.instancemode.api.FineractInstanceModeConstants;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
@@ -27,11 +28,14 @@ public class EnableFineractEventsCondition implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
boolean isReadModeEnabled = Optional.ofNullable(context.getEnvironment().getProperty("fineract.mode.read-enabled", Boolean.class))
boolean isReadModeEnabled = Optional.ofNullable(
context.getEnvironment().getProperty(FineractInstanceModeConstants.FINERACT_MODE_READ_ENABLE_PROPERTY, Boolean.class))
.orElse(true);
boolean isWriteModeEnabled = Optional.ofNullable(context.getEnvironment().getProperty("fineract.mode.write-enabled", Boolean.class))
boolean isWriteModeEnabled = Optional.ofNullable(
context.getEnvironment().getProperty(FineractInstanceModeConstants.FINERACT_MODE_WRITE_ENABLE_PROPERTY, Boolean.class))
.orElse(true);
boolean isBatchModeEnabled = Optional.ofNullable(context.getEnvironment().getProperty("fineract.mode.batch-enabled", Boolean.class))
boolean isBatchModeEnabled = Optional.ofNullable(
context.getEnvironment().getProperty(FineractInstanceModeConstants.FINERACT_MODE_BATCH_ENABLE_PROPERTY, Boolean.class))
.orElse(true);
return !isReadModeEnabled && (isWriteModeEnabled || isBatchModeEnabled);
}
@@ -0,0 +1,31 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.instancemode.api;
public final class FineractInstanceModeConstants {
private FineractInstanceModeConstants() {
}
public static final String FINERACT_MODE_READ_ENABLE_PROPERTY = "fineract.mode.read-enabled";
public static final String FINERACT_MODE_WRITE_ENABLE_PROPERTY = "fineract.mode.write-enabled";
public static final String FINERACT_MODE_BATCH_ENABLE_PROPERTY = "fineract.mode.batch-enabled";
}
@@ -23,7 +23,7 @@ import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.Session;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.config.EnableFineractEventsCondition;
import org.apache.fineract.infrastructure.core.config.EnableFineractEventListenerCondition;
import org.apache.fineract.notification.data.NotificationData;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Profile;
@@ -32,7 +32,7 @@ import org.springframework.stereotype.Component;
@Component
@Profile("activeMqEnabled")
@Conditional(EnableFineractEventsCondition.class)
@Conditional(EnableFineractEventListenerCondition.class)
@RequiredArgsConstructor
public class ActiveMQNotificationEventListener implements SessionAwareMessageListener {