48
48
@ ConditionalOnMissingBean (ConnectionFactory .class )
49
49
class ActiveMQConnectionFactoryConfiguration {
50
50
51
+ private static ActiveMQConnectionFactory createConnectionFactory (ActiveMQProperties properties ,
52
+ List <ActiveMQConnectionFactoryCustomizer > connectionFactoryCustomizers ) {
53
+ return new ActiveMQConnectionFactoryFactory (properties , connectionFactoryCustomizers )
54
+ .createConnectionFactory (ActiveMQConnectionFactory .class );
55
+ }
56
+
51
57
@ Configuration
52
- @ ConditionalOnClass (CachingConnectionFactory .class )
53
58
@ ConditionalOnProperty (prefix = "spring.activemq.pool" , name = "enabled" , havingValue = "false" ,
54
59
matchIfMissing = true )
55
60
static class SimpleConnectionFactoryConfiguration {
56
61
57
- private final JmsProperties jmsProperties ;
58
-
59
- private final ActiveMQProperties properties ;
60
-
61
- private final List <ActiveMQConnectionFactoryCustomizer > connectionFactoryCustomizers ;
62
-
63
- SimpleConnectionFactoryConfiguration (JmsProperties jmsProperties , ActiveMQProperties properties ,
62
+ @ Bean
63
+ @ ConditionalOnProperty (prefix = "spring.jms.cache" , name = "enabled" , havingValue = "false" )
64
+ public ActiveMQConnectionFactory jmsConnectionFactory (ActiveMQProperties properties ,
64
65
ObjectProvider <ActiveMQConnectionFactoryCustomizer > connectionFactoryCustomizers ) {
65
- this .jmsProperties = jmsProperties ;
66
- this .properties = properties ;
67
- this .connectionFactoryCustomizers = connectionFactoryCustomizers .orderedStream ()
68
- .collect (Collectors .toList ());
66
+ return createConnectionFactory (properties ,
67
+ connectionFactoryCustomizers .orderedStream ().collect (Collectors .toList ()));
69
68
}
70
69
71
- @ Bean
70
+ @ ConditionalOnClass ( CachingConnectionFactory . class )
72
71
@ ConditionalOnProperty (prefix = "spring.jms.cache" , name = "enabled" , havingValue = "true" ,
73
72
matchIfMissing = true )
74
- public CachingConnectionFactory cachingJmsConnectionFactory () {
75
- JmsProperties .Cache cacheProperties = this .jmsProperties .getCache ();
76
- CachingConnectionFactory connectionFactory = new CachingConnectionFactory (createConnectionFactory ());
77
- connectionFactory .setCacheConsumers (cacheProperties .isConsumers ());
78
- connectionFactory .setCacheProducers (cacheProperties .isProducers ());
79
- connectionFactory .setSessionCacheSize (cacheProperties .getSessionCacheSize ());
80
- return connectionFactory ;
81
- }
82
-
83
- @ Bean
84
- @ ConditionalOnProperty (prefix = "spring.jms.cache" , name = "enabled" , havingValue = "false" )
85
- public ActiveMQConnectionFactory jmsConnectionFactory () {
86
- return createConnectionFactory ();
87
- }
73
+ static class CachingConnectionFactoryConfiguration {
74
+
75
+ @ Bean
76
+ @ ConditionalOnProperty (prefix = "spring.jms.cache" , name = "enabled" , havingValue = "true" ,
77
+ matchIfMissing = true )
78
+ public CachingConnectionFactory cachingJmsConnectionFactory (JmsProperties jmsProperties ,
79
+ ActiveMQProperties properties ,
80
+ ObjectProvider <ActiveMQConnectionFactoryCustomizer > connectionFactoryCustomizers ) {
81
+ JmsProperties .Cache cacheProperties = jmsProperties .getCache ();
82
+ CachingConnectionFactory connectionFactory = new CachingConnectionFactory (createConnectionFactory (
83
+ properties , connectionFactoryCustomizers .orderedStream ().collect (Collectors .toList ())));
84
+ connectionFactory .setCacheConsumers (cacheProperties .isConsumers ());
85
+ connectionFactory .setCacheProducers (cacheProperties .isProducers ());
86
+ connectionFactory .setSessionCacheSize (cacheProperties .getSessionCacheSize ());
87
+ return connectionFactory ;
88
+ }
88
89
89
- private ActiveMQConnectionFactory createConnectionFactory () {
90
- return new ActiveMQConnectionFactoryFactory (this .properties , this .connectionFactoryCustomizers )
91
- .createConnectionFactory (ActiveMQConnectionFactory .class );
92
90
}
93
91
94
92
}
@@ -98,13 +96,11 @@ private ActiveMQConnectionFactory createConnectionFactory() {
98
96
static class PooledConnectionFactoryConfiguration {
99
97
100
98
@ Bean (destroyMethod = "stop" )
101
- @ ConditionalOnProperty (prefix = "spring.activemq.pool" , name = "enabled" , havingValue = "true" ,
102
- matchIfMissing = false )
99
+ @ ConditionalOnProperty (prefix = "spring.activemq.pool" , name = "enabled" , havingValue = "true" )
103
100
public JmsPoolConnectionFactory pooledJmsConnectionFactory (ActiveMQProperties properties ,
104
101
ObjectProvider <ActiveMQConnectionFactoryCustomizer > factoryCustomizers ) {
105
- ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory (properties ,
106
- factoryCustomizers .orderedStream ().collect (Collectors .toList ()))
107
- .createConnectionFactory (ActiveMQConnectionFactory .class );
102
+ ActiveMQConnectionFactory connectionFactory = createConnectionFactory (properties ,
103
+ factoryCustomizers .orderedStream ().collect (Collectors .toList ()));
108
104
return new JmsPoolConnectionFactoryFactory (properties .getPool ())
109
105
.createPooledConnectionFactory (connectionFactory );
110
106
}
0 commit comments