|
19 | 19 | import javax.jms.ConnectionFactory;
|
20 | 20 |
|
21 | 21 | import org.apache.activemq.ActiveMQConnectionFactory;
|
22 |
| -import org.apache.activemq.transport.vm.VMTransportFactory; |
| 22 | +import org.springframework.boot.autoconfigure.AutoConfigureAfter; |
23 | 23 | import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
24 | 24 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
25 |
| -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; |
26 | 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
27 | 26 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
28 |
| -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; |
29 | 27 | import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
|
30 |
| -import org.springframework.context.annotation.ConditionContext; |
31 |
| -import org.springframework.context.annotation.Conditional; |
| 28 | +import org.springframework.boot.autoconfigure.jta.JtaAutoConfiguration; |
| 29 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; |
32 | 30 | import org.springframework.context.annotation.Configuration;
|
33 | 31 | import org.springframework.context.annotation.Import;
|
34 |
| -import org.springframework.core.type.AnnotatedTypeMetadata; |
35 | 32 |
|
36 | 33 | /**
|
37 | 34 | * {@link EnableAutoConfiguration Auto-configuration} to integrate with an ActiveMQ
|
38 | 35 | * broker. Validates that the classpath contain the necessary classes before starting an
|
39 | 36 | * embedded broker.
|
40 | 37 | *
|
41 | 38 | * @author Stephane Nicoll
|
| 39 | + * @author Phillip Webb |
42 | 40 | * @since 1.1.0
|
43 | 41 | */
|
44 | 42 | @Configuration
|
45 | 43 | @AutoConfigureBefore(JmsAutoConfiguration.class)
|
| 44 | +@AutoConfigureAfter(JtaAutoConfiguration.class) |
46 | 45 | @ConditionalOnClass({ ConnectionFactory.class, ActiveMQConnectionFactory.class })
|
47 | 46 | @ConditionalOnMissingBean(ConnectionFactory.class)
|
| 47 | +@EnableConfigurationProperties(ActiveMQProperties.class) |
| 48 | +@Import({ ActiveMQXAConnectionFactoryConfiguration.class, ActiveMQConnectionFactoryConfiguration.class }) |
48 | 49 | public class ActiveMQAutoConfiguration {
|
49 | 50 |
|
50 |
| - @Configuration |
51 |
| - @ConditionalOnClass(VMTransportFactory.class) |
52 |
| - @Conditional(EmbeddedBrokerCondition.class) |
53 |
| - @Import(ActiveMQConnectionFactoryConfiguration.class) |
54 |
| - protected static class EmbeddedBroker { |
55 |
| - } |
56 |
| - |
57 |
| - @Configuration |
58 |
| - @Conditional(NonEmbeddedBrokerCondition.class) |
59 |
| - @Import(ActiveMQConnectionFactoryConfiguration.class) |
60 |
| - protected static class NetworkBroker { |
61 |
| - } |
62 |
| - |
63 |
| - static abstract class BrokerTypeCondition extends SpringBootCondition { |
64 |
| - private final boolean embedded; |
65 |
| - |
66 |
| - BrokerTypeCondition(boolean embedded) { |
67 |
| - this.embedded = embedded; |
68 |
| - } |
69 |
| - |
70 |
| - @Override |
71 |
| - public ConditionOutcome getMatchOutcome(ConditionContext context, |
72 |
| - AnnotatedTypeMetadata metadata) { |
73 |
| - String brokerUrl = ActiveMQProperties.determineBrokerUrl(context |
74 |
| - .getEnvironment()); |
75 |
| - boolean match = brokerUrl.contains("vm://"); |
76 |
| - boolean outcome = (match == this.embedded); |
77 |
| - return new ConditionOutcome(outcome, buildMessage(brokerUrl, outcome)); |
78 |
| - } |
79 |
| - |
80 |
| - protected String buildMessage(String brokerUrl, boolean outcome) { |
81 |
| - String brokerType = this.embedded ? "Embedded" : "Network"; |
82 |
| - String detected = outcome ? "detected" : "not detected"; |
83 |
| - return brokerType + " ActiveMQ broker " + detected + " - brokerUrl '" |
84 |
| - + brokerUrl + "'"; |
85 |
| - } |
86 |
| - |
87 |
| - } |
88 |
| - |
89 |
| - static class EmbeddedBrokerCondition extends BrokerTypeCondition { |
90 |
| - |
91 |
| - EmbeddedBrokerCondition() { |
92 |
| - super(true); |
93 |
| - } |
94 |
| - |
95 |
| - } |
96 |
| - |
97 |
| - static class NonEmbeddedBrokerCondition extends BrokerTypeCondition { |
98 |
| - |
99 |
| - NonEmbeddedBrokerCondition() { |
100 |
| - super(false); |
101 |
| - } |
102 |
| - |
103 |
| - } |
104 |
| - |
105 | 51 | }
|
0 commit comments