diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/config/MessagingConfig.java b/src/main/java/uk/gov/hmcts/reform/sscs/config/MessagingConfig.java index 3bf221ffc8e..cf2e9fd8c8f 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/config/MessagingConfig.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/config/MessagingConfig.java @@ -4,6 +4,7 @@ import javax.net.ssl.SSLContext; import lombok.extern.slf4j.Slf4j; import org.apache.qpid.jms.JmsConnectionFactory; +import org.apache.qpid.jms.policy.JmsDefaultPrefetchPolicy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; @@ -14,7 +15,6 @@ import org.springframework.jms.connection.CachingConnectionFactory; import org.springframework.jms.core.JmsTemplate; - @Configuration @Slf4j @EnableJms @@ -32,7 +32,9 @@ public ConnectionFactory jmsConnectionFactory(@Value("${spring.application.name} @Value("${amqp.username}") final String username, @Value("${amqp.password}") final String password, @Autowired final String jmsUrlString, - @Autowired(required = false) final SSLContext jmsSslContext) { + @Autowired(required = false) final SSLContext jmsSslContext, + @Value("${amqp.prefetch.override}") final boolean prefetchOverride, + @Value("${amqp.prefetch.topicPrefetch}") final int topicPrefetch) { JmsConnectionFactory jmsConnectionFactory = new JmsConnectionFactory(jmsUrlString); jmsConnectionFactory.setUsername(username); jmsConnectionFactory.setPassword(password); @@ -41,7 +43,12 @@ public ConnectionFactory jmsConnectionFactory(@Value("${spring.application.name} if (jmsSslContext != null) { jmsConnectionFactory.setSslContext(jmsSslContext); } - + if (prefetchOverride) { + JmsDefaultPrefetchPolicy prefetchPolicy = new JmsDefaultPrefetchPolicy(); + prefetchPolicy.setTopicPrefetch(topicPrefetch); + prefetchPolicy.setDurableTopicPrefetch(topicPrefetch); + jmsConnectionFactory.setPrefetchPolicy(prefetchPolicy); + } return new CachingConnectionFactory(jmsConnectionFactory); } @@ -62,5 +69,4 @@ public JmsListenerContainerFactory topicJmsListenerContainerFactory(ConnectionFa returnValue.setExceptionListener(t -> log.error("Exception while processing JMS message", t)); return returnValue; } - } diff --git a/src/main/resources/config/application.properties b/src/main/resources/config/application.properties index bf7e22db47a..e8422b4ae11 100644 --- a/src/main/resources/config/application.properties +++ b/src/main/resources/config/application.properties @@ -182,6 +182,8 @@ amqp.password=${AMQP_PASSWORD:} amqp.topic=${TOPIC_NAME:sscs-topic} amqp.subscription=${SUBSCRIPTION_NAME:test.queue} amqp.trustAllCerts=${TRUST_ALL_CERTS:true} +amqp.prefetch.override=${AMQP_PREFETCH_OVERRIDE:false} +amqp.prefetch.topicPrefetch=${AMQP_TOPIC_PREFETCH:1} docmosis.template.english.dl6.name=TB-SCS-GNO-ENG-00010.doc docmosis.template.english.dl16.name=TB-SCS-GNO-ENG-00011.doc