commit
9c6a744fc9
|
@ -57,7 +57,7 @@ class ArtemisConnectionFactoryConfiguration {
|
||||||
private static ActiveMQConnectionFactory createJmsConnectionFactory(ArtemisProperties properties,
|
private static ActiveMQConnectionFactory createJmsConnectionFactory(ArtemisProperties properties,
|
||||||
ArtemisConnectionDetails connectionDetails, ListableBeanFactory beanFactory) {
|
ArtemisConnectionDetails connectionDetails, ListableBeanFactory beanFactory) {
|
||||||
return new ArtemisConnectionFactoryFactory(beanFactory, properties, connectionDetails)
|
return new ArtemisConnectionFactoryFactory(beanFactory, properties, connectionDetails)
|
||||||
.createConnectionFactory(ActiveMQConnectionFactory.class);
|
.createConnectionFactory(ActiveMQConnectionFactory::new, ActiveMQConnectionFactory::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ -93,7 +93,7 @@ class ArtemisConnectionFactoryConfiguration {
|
||||||
ArtemisConnectionDetails connectionDetails) {
|
ArtemisConnectionDetails connectionDetails) {
|
||||||
ActiveMQConnectionFactory connectionFactory = new ArtemisConnectionFactoryFactory(beanFactory, properties,
|
ActiveMQConnectionFactory connectionFactory = new ArtemisConnectionFactoryFactory(beanFactory, properties,
|
||||||
connectionDetails)
|
connectionDetails)
|
||||||
.createConnectionFactory(ActiveMQConnectionFactory.class);
|
.createConnectionFactory(ActiveMQConnectionFactory::new, ActiveMQConnectionFactory::new);
|
||||||
return new JmsPoolConnectionFactoryFactory(properties.getPool())
|
return new JmsPoolConnectionFactoryFactory(properties.getPool())
|
||||||
.createPooledConnectionFactory(connectionFactory);
|
.createPooledConnectionFactory(connectionFactory);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.jms.artemis;
|
package org.springframework.boot.autoconfigure.jms.artemis;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
||||||
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
|
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
|
||||||
|
@ -61,10 +61,11 @@ class ArtemisConnectionFactoryFactory {
|
||||||
this.connectionDetails = connectionDetails;
|
this.connectionDetails = connectionDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
<T extends ActiveMQConnectionFactory> T createConnectionFactory(Class<T> factoryClass) {
|
<T extends ActiveMQConnectionFactory> T createConnectionFactory(Function<String, T> nativeFactoryCreator,
|
||||||
|
Function<ServerLocator, T> embeddedFactoryCreator) {
|
||||||
try {
|
try {
|
||||||
startEmbeddedJms();
|
startEmbeddedJms();
|
||||||
return doCreateConnectionFactory(factoryClass);
|
return doCreateConnectionFactory(nativeFactoryCreator, embeddedFactoryCreator);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new IllegalStateException("Unable to create ActiveMQConnectionFactory", ex);
|
throw new IllegalStateException("Unable to create ActiveMQConnectionFactory", ex);
|
||||||
|
@ -84,15 +85,16 @@ class ArtemisConnectionFactoryFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends ActiveMQConnectionFactory> T doCreateConnectionFactory(Class<T> factoryClass) throws Exception {
|
private <T extends ActiveMQConnectionFactory> T doCreateConnectionFactory(Function<String, T> nativeFactoryCreator,
|
||||||
|
Function<ServerLocator, T> embeddedFactoryCreator) throws Exception {
|
||||||
ArtemisMode mode = this.connectionDetails.getMode();
|
ArtemisMode mode = this.connectionDetails.getMode();
|
||||||
if (mode == null) {
|
if (mode == null) {
|
||||||
mode = deduceMode();
|
mode = deduceMode();
|
||||||
}
|
}
|
||||||
if (mode == ArtemisMode.EMBEDDED) {
|
if (mode == ArtemisMode.EMBEDDED) {
|
||||||
return createEmbeddedConnectionFactory(factoryClass);
|
return createEmbeddedConnectionFactory(embeddedFactoryCreator);
|
||||||
}
|
}
|
||||||
return createNativeConnectionFactory(factoryClass);
|
return createNativeConnectionFactory(nativeFactoryCreator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,13 +117,13 @@ class ArtemisConnectionFactoryFactory {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends ActiveMQConnectionFactory> T createEmbeddedConnectionFactory(Class<T> factoryClass)
|
private <T extends ActiveMQConnectionFactory> T createEmbeddedConnectionFactory(
|
||||||
throws Exception {
|
Function<ServerLocator, T> factoryCreator) throws Exception {
|
||||||
try {
|
try {
|
||||||
TransportConfiguration transportConfiguration = new TransportConfiguration(
|
TransportConfiguration transportConfiguration = new TransportConfiguration(
|
||||||
InVMConnectorFactory.class.getName(), this.properties.getEmbedded().generateTransportParameters());
|
InVMConnectorFactory.class.getName(), this.properties.getEmbedded().generateTransportParameters());
|
||||||
ServerLocator serviceLocator = ActiveMQClient.createServerLocatorWithoutHA(transportConfiguration);
|
ServerLocator serverLocator = ActiveMQClient.createServerLocatorWithoutHA(transportConfiguration);
|
||||||
return factoryClass.getConstructor(ServerLocator.class).newInstance(serviceLocator);
|
return factoryCreator.apply(serverLocator);
|
||||||
}
|
}
|
||||||
catch (NoClassDefFoundError ex) {
|
catch (NoClassDefFoundError ex) {
|
||||||
throw new IllegalStateException("Unable to create InVM "
|
throw new IllegalStateException("Unable to create InVM "
|
||||||
|
@ -129,9 +131,8 @@ class ArtemisConnectionFactoryFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends ActiveMQConnectionFactory> T createNativeConnectionFactory(Class<T> factoryClass)
|
private <T extends ActiveMQConnectionFactory> T createNativeConnectionFactory(Function<String, T> factoryCreator) {
|
||||||
throws Exception {
|
T connectionFactory = newNativeConnectionFactory(factoryCreator);
|
||||||
T connectionFactory = newNativeConnectionFactory(factoryClass);
|
|
||||||
String user = this.connectionDetails.getUser();
|
String user = this.connectionDetails.getUser();
|
||||||
if (StringUtils.hasText(user)) {
|
if (StringUtils.hasText(user)) {
|
||||||
connectionFactory.setUser(user);
|
connectionFactory.setUser(user);
|
||||||
|
@ -140,12 +141,10 @@ class ArtemisConnectionFactoryFactory {
|
||||||
return connectionFactory;
|
return connectionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends ActiveMQConnectionFactory> T newNativeConnectionFactory(Class<T> factoryClass) throws Exception {
|
private <T extends ActiveMQConnectionFactory> T newNativeConnectionFactory(Function<String, T> factoryCreator) {
|
||||||
String brokerUrl = StringUtils.hasText(this.connectionDetails.getBrokerUrl())
|
String brokerUrl = StringUtils.hasText(this.connectionDetails.getBrokerUrl())
|
||||||
? this.connectionDetails.getBrokerUrl() : DEFAULT_BROKER_URL;
|
? this.connectionDetails.getBrokerUrl() : DEFAULT_BROKER_URL;
|
||||||
Constructor<T> constructor = factoryClass.getConstructor(String.class);
|
return factoryCreator.apply(brokerUrl);
|
||||||
return constructor.newInstance(brokerUrl);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,14 +47,14 @@ class ArtemisXAConnectionFactoryConfiguration {
|
||||||
ArtemisConnectionDetails connectionDetails, XAConnectionFactoryWrapper wrapper) throws Exception {
|
ArtemisConnectionDetails connectionDetails, XAConnectionFactoryWrapper wrapper) throws Exception {
|
||||||
return wrapper
|
return wrapper
|
||||||
.wrapConnectionFactory(new ArtemisConnectionFactoryFactory(beanFactory, properties, connectionDetails)
|
.wrapConnectionFactory(new ArtemisConnectionFactoryFactory(beanFactory, properties, connectionDetails)
|
||||||
.createConnectionFactory(ActiveMQXAConnectionFactory.class));
|
.createConnectionFactory(ActiveMQXAConnectionFactory::new, ActiveMQXAConnectionFactory::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
ActiveMQXAConnectionFactory nonXaJmsConnectionFactory(ListableBeanFactory beanFactory, ArtemisProperties properties,
|
ActiveMQXAConnectionFactory nonXaJmsConnectionFactory(ListableBeanFactory beanFactory, ArtemisProperties properties,
|
||||||
ArtemisConnectionDetails connectionDetails) {
|
ArtemisConnectionDetails connectionDetails) {
|
||||||
return new ArtemisConnectionFactoryFactory(beanFactory, properties, connectionDetails)
|
return new ArtemisConnectionFactoryFactory(beanFactory, properties, connectionDetails)
|
||||||
.createConnectionFactory(ActiveMQXAConnectionFactory.class);
|
.createConnectionFactory(ActiveMQXAConnectionFactory::new, ActiveMQXAConnectionFactory::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue