// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 package app.settlement.inbound.config; import lombok.extern.slf4j.Slf4j; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQSession; import org.apache.activemq.RedeliveryPolicy; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jms.config.DefaultJmsListenerContainerFactory; import org.springframework.jms.config.JmsListenerContainerFactory; import javax.jms.ConnectionFactory; @Slf4j @Configuration public class ReceiverConfig { @Value("${spring.activemq.broker-url}") private String brokerUrl; @Value("${spring.activemq.user}") private String userName; @Value("${spring.activemq.password}") private String password; @Bean public ActiveMQConnectionFactory connectionFactory() { log.info("Using ReceiverConfig:"); log.info("brokerUrl: " + brokerUrl); log.info("userName: " + userName); ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(); activeMQConnectionFactory.setBrokerURL(brokerUrl); activeMQConnectionFactory.setUserName(userName); activeMQConnectionFactory.setPassword(password); RedeliveryPolicy policy = activeMQConnectionFactory.getRedeliveryPolicy(); policy.setMaximumRedeliveries(-1); activeMQConnectionFactory.setRedeliveryPolicy(policy); return activeMQConnectionFactory; } @Bean public JmsListenerContainerFactory jmsFactory(ConnectionFactory connectionFactory, DefaultJmsListenerContainerFactoryConfigurer configurer) { DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); configurer.configure(factory, connectionFactory); factory.setErrorHandler(t -> { log.error("Error in listener!", t); }); factory.setSessionAcknowledgeMode(ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE); factory.setSessionTransacted(false); factory.setAutoStartup(false); return factory; } }