001/* 002 * The contents of this file are subject to the license and copyright 003 * detailed in the LICENSE and NOTICE files at the root of the source 004 * tree. 005 */ 006package org.fcrepo.camel.activemq; 007 008import org.apache.activemq.ActiveMQConnectionFactory; 009import org.apache.activemq.pool.PooledConnectionFactory; 010import org.apache.camel.component.activemq.ActiveMQComponent; 011import org.apache.camel.component.jms.JmsConfiguration; 012import org.fcrepo.camel.common.config.BasePropsConfig; 013import org.springframework.beans.factory.annotation.Value; 014import org.springframework.context.annotation.Bean; 015import org.springframework.context.annotation.Configuration; 016 017import javax.jms.ConnectionFactory; 018 019/** 020 * @author dbernstein 021 */ 022@Configuration 023public class ActiveMQConfig extends BasePropsConfig { 024 @Value("${jms.brokerUrl:tcp://localhost:61616}") 025 private String jmsBrokerUrl; 026 027 @Value("${jms.username:#{null}}") 028 private String jmsUsername; 029 030 @Value("${jms.password:#{null}}") 031 private String jmsPasword; 032 033 @Value("${jms.connections:10}") 034 private int jmsConnections; 035 036 @Value("${jms.consumers:1}") 037 private int jmsConsumers; 038 039 040 @Bean 041 public ActiveMQConnectionFactory connectionFactory() { 042 final var connectionFactory = new ActiveMQConnectionFactory(); 043 connectionFactory.setBrokerURL(jmsBrokerUrl); 044 connectionFactory.setUserName(jmsUsername); 045 connectionFactory.setPassword(jmsPasword); 046 return connectionFactory; 047 } 048 049 @Bean 050 public ConnectionFactory pooledConnectionFactory(final ActiveMQConnectionFactory connectionFactory) { 051 final var pooledConnectionFactory = new PooledConnectionFactory(); 052 pooledConnectionFactory.setMaxConnections(jmsConnections); 053 pooledConnectionFactory.setConnectionFactory(connectionFactory); 054 return pooledConnectionFactory; 055 } 056 057 @Bean 058 public JmsConfiguration jmsConfiguration(final PooledConnectionFactory connectionFactory) { 059 final var configuration = new JmsConfiguration(); 060 configuration.setConcurrentConsumers(jmsConsumers); 061 configuration.setConnectionFactory(connectionFactory); 062 return configuration; 063 } 064 065 @Bean("broker") 066 public ActiveMQComponent activeMQComponent(final JmsConfiguration jmsConfiguration) { 067 final var component = new ActiveMQComponent(); 068 component.setConfiguration(jmsConfiguration); 069 return component; 070 } 071} 072