FINERACT-1694 JMS ActiveMQ downstream channel integration for events

This commit is contained in:
Ruchi Dhamankar
2022-09-27 17:06:29 +02:00
committed by Aleksandar Vidakovic
parent 18ebb3be6c
commit ee0184c0a5
12 changed files with 299 additions and 15 deletions
@@ -30,6 +30,7 @@ import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfigurat
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@@ -45,6 +46,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableWebSecurity
@EnableConfigurationProperties({ FineractProperties.class, LiquibaseProperties.class })
@ComponentScan(basePackages = "org.apache.fineract.**")
@IntegrationComponentScan(basePackages = "org.apache.fineract.**")
public abstract class AbstractApplicationConfiguration {
}
@@ -151,5 +151,6 @@ public class FineractProperties {
private boolean enabled;
private String eventQueueName;
private String brokerUrl;
}
}
@@ -0,0 +1,42 @@
/**
* 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.config;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.fineract.infrastructure.core.config.FineractProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConditionalOnProperty(value = "fineract.events.external.producer.jms.enabled", havingValue = "true")
public class ExternalEventJMSBrokerConfiguration {
@Autowired
private FineractProperties fineractProperties;
@Bean
public ActiveMQConnectionFactory connectionFactory() {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL(fineractProperties.getEvents().getExternal().getProducer().getJms().getBrokerUrl());
connectionFactory.setTrustAllPackages(true);
return connectionFactory;
}
}
@@ -0,0 +1,56 @@
/**
* 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.config;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.fineract.infrastructure.core.config.FineractProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.handler.LoggingHandler;
import org.springframework.integration.jms.dsl.Jms;
@Configuration
@EnableIntegration
@ConditionalOnProperty(value = "fineract.events.external.producer.jms.enabled", havingValue = "true")
@Import(value = { ExternalEventJMSBrokerConfiguration.class })
public class ExternalEventJMSProducerConfiguration {
@Autowired
private DirectChannel outboundRequests;
@Autowired
private FineractProperties fineractProperties;
@Bean
public IntegrationFlow outboundFlow(ActiveMQConnectionFactory connectionFactory) {
return IntegrationFlows.from(outboundRequests) //
.log(LoggingHandler.Level.DEBUG) //
.handle(Jms.outboundAdapter(connectionFactory)
.destination(fineractProperties.getEvents().getExternal().getProducer().getJms().getEventQueueName()))
.get();
}
}
@@ -0,0 +1,36 @@
/**
* 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.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.config.EnableIntegration;
@Configuration
@EnableIntegration
@ConditionalOnProperty(value = "fineract.events.external.enabled", havingValue = "true")
public class ExternalEventProducerConfiguration {
@Bean
public DirectChannel outboundRequests() {
return new DirectChannel();
}
}
@@ -18,6 +18,7 @@
*/
package org.apache.fineract.infrastructure.event.external.jobs;
import java.io.IOException;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -29,6 +30,7 @@ import org.apache.fineract.infrastructure.event.external.repository.ExternalEven
import org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEvent;
import org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEventStatus;
import org.apache.fineract.infrastructure.event.external.service.message.MessageFactory;
import org.apache.fineract.infrastructure.event.external.service.support.ByteBufferConverter;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
@@ -46,6 +48,7 @@ public class SendAsynchronousEventsTasklet implements Tasklet {
private final ExternalEventRepository repository;
private final ExternalEventProducer eventProducer;
private final MessageFactory messageFactory;
private final ByteBufferConverter byteBufferConverter;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
@@ -65,10 +68,10 @@ public class SendAsynchronousEventsTasklet implements Tasklet {
return events;
}
private void processEvents(List<ExternalEvent> queuedEvents) {
private void processEvents(List<ExternalEvent> queuedEvents) throws IOException {
for (ExternalEvent event : queuedEvents) {
MessageV1 message = messageFactory.createMessage(event);
eventProducer.sendEvent(message);
eventProducer.sendEvent(byteBufferConverter.convert(message.toByteBuffer()));
event.setStatus(ExternalEventStatus.SENT);
event.setSentAt(DateUtils.getOffsetDateTimeOfTenant());
repository.save(event);
@@ -18,15 +18,16 @@
*/
package org.apache.fineract.infrastructure.event.external.producer;
import org.apache.fineract.avro.MessageV1;
import org.apache.fineract.infrastructure.event.external.exception.AcknowledgementTimeoutException;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
@Service
public class ExternalEventProducerImpl implements ExternalEventProducer {
@ConditionalOnProperty(value = "fineract.events.external.enabled", havingValue = "false")
public class DummyExternalEventProducerImpl implements ExternalEventProducer {
@Override
public void sendEvent(MessageV1 message) throws AcknowledgementTimeoutException {
public void sendEvent(byte[] message) throws AcknowledgementTimeoutException {
return;
}
}
@@ -18,10 +18,15 @@
*/
package org.apache.fineract.infrastructure.event.external.producer;
import org.apache.fineract.avro.MessageV1;
import org.apache.fineract.infrastructure.event.external.exception.AcknowledgementTimeoutException;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.integration.annotation.Gateway;
import org.springframework.integration.annotation.MessagingGateway;
@MessagingGateway(name = "externalEventGateway")
@ConditionalOnProperty(value = "fineract.events.external.enabled", havingValue = "true")
public interface ExternalEventProducer {
void sendEvent(MessageV1 message) throws AcknowledgementTimeoutException;
@Gateway(requestChannel = "outboundRequests", replyTimeout = 2, requestTimeout = 200)
void sendEvent(byte[] message) throws AcknowledgementTimeoutException;
}
@@ -57,6 +57,7 @@ fineract.events.external.enabled=${FINERACT_EXTERNAL_EVENTS_ENABLED:false}
fineract.events.external.producer.read-batch-size=${FINERACT_EXTERNAL_EVENTS_PRODUCER_READ_BATCH_SIZE:1000}
fineract.events.external.producer.jms.enabled=${FINERACT_EXTERNAL_EVENTS_PRODUCER_JMS_ENABLED:false}
fineract.events.external.producer.jms.event-queue-name=${FINERACT_EXTERNAL_EVENTS_PRODUCER_JMS_QUEUE_NAME:JMS-event-queue}
fineract.events.external.producer.jms.broker-url=${FINERACT_EXTERNAL_EVENTS_PRODUCER_JMS_BROKER_URL:tcp://127.0.0.1:61616}
# Logging pattern for the console