diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java index ad4abe2f3..231a93632 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/FineractProperties.java @@ -191,6 +191,7 @@ public class FineractProperties { private String brokerUsername; private String brokerPassword; private int producerCount; + private boolean asyncSendEnabled; public boolean isBrokerPasswordProtected() { return StringUtils.isNotBlank(brokerUsername) || StringUtils.isNotBlank(brokerPassword); diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/config/ExternalEventJMSConfiguration.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/config/ExternalEventJMSConfiguration.java index 3b384b672..228b155da 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/config/ExternalEventJMSConfiguration.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/config/ExternalEventJMSConfiguration.java @@ -43,6 +43,7 @@ public class ExternalEventJMSConfiguration { FineractExternalEventsProducerJmsProperties jmsProps = fineractProperties.getEvents().getExternal().getProducer().getJms(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); connectionFactory.setBrokerURL(jmsProps.getBrokerUrl()); + connectionFactory.setUseAsyncSend(jmsProps.isAsyncSendEnabled()); connectionFactory.setTrustAllPackages(true); if (jmsProps.isBrokerPasswordProtected()) { connectionFactory.setUserName(jmsProps.getBrokerUsername()); diff --git a/fineract-provider/src/main/resources/application.properties b/fineract-provider/src/main/resources/application.properties index 0545d1b14..4d07b7230 100644 --- a/fineract-provider/src/main/resources/application.properties +++ b/fineract-provider/src/main/resources/application.properties @@ -72,6 +72,7 @@ fineract.remote-job-message-handler.jms.broker-password=${FINERACT_REMOTE_JOB_ME fineract.events.external.enabled=${FINERACT_EXTERNAL_EVENTS_ENABLED:false} fineract.events.external.producer.jms.enabled=${FINERACT_EXTERNAL_EVENTS_PRODUCER_JMS_ENABLED:false} +fineract.events.external.producer.jms.async-send-enabled=${FINERACT_EXTERNAL_EVENTS_PRODUCER_JMS_ASYNC_SEND_ENABLED:false} fineract.events.external.producer.jms.event-queue-name=${FINERACT_EXTERNAL_EVENTS_PRODUCER_JMS_QUEUE_NAME:} fineract.events.external.producer.jms.event-topic-name=${FINERACT_EXTERNAL_EVENTS_PRODUCER_JMS_TOPIC_NAME:} fineract.events.external.producer.jms.broker-url=${FINERACT_EXTERNAL_EVENTS_PRODUCER_JMS_BROKER_URL:tcp://127.0.0.1:61616} diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/repository/domain/ExternalEventTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/repository/domain/ExternalEventTest.java new file mode 100644 index 000000000..02f12a8d9 --- /dev/null +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/repository/domain/ExternalEventTest.java @@ -0,0 +1,61 @@ +/** + * 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.event.external.repository.domain; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.LocalDate; +import java.util.HashMap; +import java.util.Map; +import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; +import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; +import org.junit.jupiter.api.Test; + +class ExternalEventTest { + + @Test + public void testConstructorWorks() { + // given + LocalDate currentBusinessDate = LocalDate.of(2022, 6, 12); + ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + ThreadLocalContextUtil.setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, currentBusinessDate))); + + String type = "type"; + String category = "category"; + String schema = "schema"; + byte[] data = new byte[0]; + String idempotencyKey = "idempotencyKey"; + long aggregateRootId = 1L; + // when + ExternalEvent result = new ExternalEvent(type, category, schema, data, idempotencyKey, aggregateRootId); + // then + assertThat(result.getType()).isEqualTo(type); + assertThat(result.getCategory()).isEqualTo(category); + assertThat(result.getSchema()).isEqualTo(schema); + assertThat(result.getData()).isEqualTo(data); + assertThat(result.getIdempotencyKey()).isEqualTo(idempotencyKey); + assertThat(result.getAggregateRootId()).isEqualTo(aggregateRootId); + assertThat(result.getStatus()).isEqualTo(ExternalEventStatus.TO_BE_SENT); + assertThat(result.getBusinessDate()).isEqualTo(currentBusinessDate); + assertThat(result.getCreatedAt()).isNotNull(); + assertThat(result.getSentAt()).isNull(); + + } +}