|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2019 the original author or authors.
|
|
|
|
|
* Copyright 2012-2020 the original author or authors.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
@ -44,6 +44,8 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
*/
|
|
|
|
|
class ArtemisConnectionFactoryFactory {
|
|
|
|
|
|
|
|
|
|
private static final String DEFAULT_BROKER_URL = "tcp://localhost:61616";
|
|
|
|
|
|
|
|
|
|
static final String[] EMBEDDED_JMS_CLASSES = { "org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS",
|
|
|
|
|
"org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ" };
|
|
|
|
|
|
|
|
|
@ -128,27 +130,32 @@ class ArtemisConnectionFactoryFactory {
|
|
|
|
|
|
|
|
|
|
private <T extends ActiveMQConnectionFactory> T createNativeConnectionFactory(Class<T> factoryClass)
|
|
|
|
|
throws Exception {
|
|
|
|
|
T connectionFactory;
|
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
|
String url = this.properties.getBrokerUrl();
|
|
|
|
|
if (StringUtils.hasText(url)) {
|
|
|
|
|
Constructor<T> constructor = factoryClass.getConstructor(String.class);
|
|
|
|
|
connectionFactory = constructor.newInstance(url);
|
|
|
|
|
T connectionFactory = newNativeConnectionFactory(factoryClass);
|
|
|
|
|
String user = this.properties.getUser();
|
|
|
|
|
if (StringUtils.hasText(user)) {
|
|
|
|
|
connectionFactory.setUser(user);
|
|
|
|
|
connectionFactory.setPassword(this.properties.getPassword());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return connectionFactory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
|
private <T extends ActiveMQConnectionFactory> T newNativeConnectionFactory(Class<T> factoryClass) throws Exception {
|
|
|
|
|
// Fallback if the broker url is not set
|
|
|
|
|
if (!StringUtils.hasText(this.properties.getBrokerUrl()) && StringUtils.hasText(this.properties.getHost())) {
|
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
|
params.put(TransportConstants.HOST_PROP_NAME, this.properties.getHost());
|
|
|
|
|
params.put(TransportConstants.PORT_PROP_NAME, this.properties.getPort());
|
|
|
|
|
TransportConfiguration transportConfiguration = new TransportConfiguration(
|
|
|
|
|
NettyConnectorFactory.class.getName(), params);
|
|
|
|
|
Constructor<T> constructor = factoryClass.getConstructor(boolean.class, TransportConfiguration[].class);
|
|
|
|
|
connectionFactory = constructor.newInstance(false, new TransportConfiguration[] { transportConfiguration });
|
|
|
|
|
return constructor.newInstance(false, new TransportConfiguration[] { transportConfiguration });
|
|
|
|
|
}
|
|
|
|
|
String user = this.properties.getUser();
|
|
|
|
|
if (StringUtils.hasText(user)) {
|
|
|
|
|
connectionFactory.setUser(user);
|
|
|
|
|
connectionFactory.setPassword(this.properties.getPassword());
|
|
|
|
|
}
|
|
|
|
|
return connectionFactory;
|
|
|
|
|
String brokerUrl = StringUtils.hasText(this.properties.getBrokerUrl()) ? this.properties.getBrokerUrl()
|
|
|
|
|
: DEFAULT_BROKER_URL;
|
|
|
|
|
Constructor<T> constructor = factoryClass.getConstructor(String.class);
|
|
|
|
|
return constructor.newInstance(brokerUrl);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|