This closes #3092
This commit is contained in:
commit
b20bca221d
|
@ -21,16 +21,29 @@ import javax.jms.Connection;
|
||||||
import javax.jms.ConnectionFactory;
|
import javax.jms.ConnectionFactory;
|
||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
import javax.jms.JMSSecurityException;
|
import javax.jms.JMSSecurityException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import io.airlift.airline.Option;
|
import io.airlift.airline.Option;
|
||||||
|
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
||||||
|
import org.apache.activemq.artemis.cli.commands.ActionContext;
|
||||||
import org.apache.activemq.artemis.cli.commands.InputAbstract;
|
import org.apache.activemq.artemis.cli.commands.InputAbstract;
|
||||||
|
import org.apache.activemq.artemis.core.config.FileDeploymentManager;
|
||||||
|
import org.apache.activemq.artemis.core.config.impl.FileConfiguration;
|
||||||
|
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
|
||||||
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
||||||
|
import org.apache.activemq.artemis.utils.ConfigurationHelper;
|
||||||
|
import org.apache.activemq.artemis.utils.uri.SchemaConstants;
|
||||||
import org.apache.qpid.jms.JmsConnectionFactory;
|
import org.apache.qpid.jms.JmsConnectionFactory;
|
||||||
|
|
||||||
public class ConnectionAbstract extends InputAbstract {
|
public class ConnectionAbstract extends InputAbstract {
|
||||||
|
|
||||||
|
private static final String DEFAULT_BROKER_URL = "tcp://localhost:61616";
|
||||||
|
|
||||||
@Option(name = "--url", description = "URL towards the broker. (default: tcp://localhost:61616)")
|
@Option(name = "--url", description = "URL towards the broker. (default: tcp://localhost:61616)")
|
||||||
protected String brokerURL = "tcp://localhost:61616";
|
protected String brokerURL = DEFAULT_BROKER_URL;
|
||||||
|
|
||||||
@Option(name = "--user", description = "User used to connect")
|
@Option(name = "--user", description = "User used to connect")
|
||||||
protected String user;
|
protected String user;
|
||||||
|
@ -79,6 +92,56 @@ public class ConnectionAbstract extends InputAbstract {
|
||||||
this.protocol = protocol;
|
this.protocol = protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object execute(ActionContext context) throws Exception {
|
||||||
|
super.execute(context);
|
||||||
|
|
||||||
|
if (brokerURL == DEFAULT_BROKER_URL) {
|
||||||
|
String brokerURLInstance = getBrokerURLInstance();
|
||||||
|
|
||||||
|
if (brokerURLInstance != null) {
|
||||||
|
brokerURL = brokerURLInstance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Connection brokerURL = " + brokerURL);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getBrokerURLInstance() {
|
||||||
|
if (getBrokerInstance() != null) {
|
||||||
|
try {
|
||||||
|
FileConfiguration fileConfiguration = new FileConfiguration();
|
||||||
|
String brokerConfiguration = new File(new File(getBrokerEtc()), "broker.xml").toURI().toASCIIString();
|
||||||
|
FileDeploymentManager fileDeploymentManager = new FileDeploymentManager(brokerConfiguration);
|
||||||
|
fileDeploymentManager.addDeployable(fileConfiguration);
|
||||||
|
fileDeploymentManager.readConfiguration();
|
||||||
|
|
||||||
|
for (TransportConfiguration acceptorConfiguration: fileConfiguration.getAcceptorConfigurations()) {
|
||||||
|
if (acceptorConfiguration.getName().equals("artemis")) {
|
||||||
|
Map<String, Object> acceptorParams = acceptorConfiguration.getParams();
|
||||||
|
String scheme = ConfigurationHelper.getStringProperty(TransportConstants.SCHEME_PROP_NAME, SchemaConstants.TCP, acceptorParams);
|
||||||
|
String host = ConfigurationHelper.getStringProperty(TransportConstants.HOST_PROP_NAME, "localhost", acceptorParams);
|
||||||
|
int port = ConfigurationHelper.getIntProperty(TransportConstants.PORT_PROP_NAME, 61616, acceptorParams);
|
||||||
|
|
||||||
|
if (InetAddress.getByName(host).isAnyLocalAddress()) {
|
||||||
|
host = "localhost";
|
||||||
|
}
|
||||||
|
|
||||||
|
return new URI(scheme, null, host, port, null, null, null).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (isVerbose()) {
|
||||||
|
System.out.print("Can not get the broker url instance: " + e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
protected ConnectionFactory createConnectionFactory() throws Exception {
|
protected ConnectionFactory createConnectionFactory() throws Exception {
|
||||||
if (protocol.equals("core")) {
|
if (protocol.equals("core")) {
|
||||||
return createCoreConnectionFactory();
|
return createCoreConnectionFactory();
|
||||||
|
|
|
@ -909,6 +909,11 @@ public class ArtemisTest extends CliTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCustomPort() throws Exception {
|
||||||
|
testSimpleRun("server", 61696);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPerfJournal() throws Exception {
|
public void testPerfJournal() throws Exception {
|
||||||
File instanceFolder = temporaryFolder.newFolder("server1");
|
File instanceFolder = temporaryFolder.newFolder("server1");
|
||||||
|
@ -924,6 +929,10 @@ public class ArtemisTest extends CliTestBase {
|
||||||
|
|
||||||
|
|
||||||
public void testSimpleRun(String folderName) throws Exception {
|
public void testSimpleRun(String folderName) throws Exception {
|
||||||
|
testSimpleRun(folderName, 61616);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSimpleRun(String folderName, int acceptorPort) throws Exception {
|
||||||
File instanceFolder = temporaryFolder.newFolder(folderName);
|
File instanceFolder = temporaryFolder.newFolder(folderName);
|
||||||
|
|
||||||
setupAuth(instanceFolder);
|
setupAuth(instanceFolder);
|
||||||
|
@ -933,7 +942,7 @@ public class ArtemisTest extends CliTestBase {
|
||||||
|
|
||||||
// This is usually set when run from the command line via artemis.profile
|
// This is usually set when run from the command line via artemis.profile
|
||||||
Run.setEmbedded(true);
|
Run.setEmbedded(true);
|
||||||
Artemis.main("create", instanceFolder.getAbsolutePath(), "--force", "--silent", "--no-web", "--queues", queues, "--addresses", addresses, "--no-autotune", "--require-login");
|
Artemis.main("create", instanceFolder.getAbsolutePath(), "--force", "--silent", "--no-web", "--queues", queues, "--addresses", addresses, "--no-autotune", "--require-login", "--default-port", Integer.toString(acceptorPort));
|
||||||
System.setProperty("artemis.instance", instanceFolder.getAbsolutePath());
|
System.setProperty("artemis.instance", instanceFolder.getAbsolutePath());
|
||||||
|
|
||||||
|
|
||||||
|
@ -941,7 +950,7 @@ public class ArtemisTest extends CliTestBase {
|
||||||
// Some exceptions may happen on the initialization, but they should be ok on start the basic core protocol
|
// Some exceptions may happen on the initialization, but they should be ok on start the basic core protocol
|
||||||
Artemis.internalExecute("run");
|
Artemis.internalExecute("run");
|
||||||
|
|
||||||
try (ServerLocator locator = ServerLocatorImpl.newLocator("tcp://localhost:61616");
|
try (ServerLocator locator = ServerLocatorImpl.newLocator("tcp://localhost:" + acceptorPort);
|
||||||
ClientSessionFactory factory = locator.createSessionFactory();
|
ClientSessionFactory factory = locator.createSessionFactory();
|
||||||
ClientSession coreSession = factory.createSession("admin", "admin", false, true, true, false, 0)) {
|
ClientSession coreSession = factory.createSession("admin", "admin", false, true, true, false, 0)) {
|
||||||
for (String str : queues.split(",")) {
|
for (String str : queues.split(",")) {
|
||||||
|
@ -973,7 +982,7 @@ public class ArtemisTest extends CliTestBase {
|
||||||
assertEquals(Integer.valueOf(10), Artemis.internalExecute("producer", "--destination", "queue://q1", "--message", "message", "--message-count", "10", "--user", "admin", "--password", "admin"));
|
assertEquals(Integer.valueOf(10), Artemis.internalExecute("producer", "--destination", "queue://q1", "--message", "message", "--message-count", "10", "--user", "admin", "--password", "admin"));
|
||||||
assertEquals(Integer.valueOf(10), Artemis.internalExecute("consumer", "--destination", "queue://q1", "--break-on-null", "--receive-timeout", "100", "--user", "admin", "--password", "admin"));
|
assertEquals(Integer.valueOf(10), Artemis.internalExecute("consumer", "--destination", "queue://q1", "--break-on-null", "--receive-timeout", "100", "--user", "admin", "--password", "admin"));
|
||||||
|
|
||||||
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
|
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:" + acceptorPort);
|
||||||
Connection connection = cf.createConnection("admin", "admin");
|
Connection connection = cf.createConnection("admin", "admin");
|
||||||
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
|
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
|
||||||
MessageProducer producer = session.createProducer(ActiveMQDestination.createDestination("queue://q1", ActiveMQDestination.TYPE.QUEUE));
|
MessageProducer producer = session.createProducer(ActiveMQDestination.createDestination("queue://q1", ActiveMQDestination.TYPE.QUEUE));
|
||||||
|
|
|
@ -108,6 +108,9 @@ public class BeanSupport {
|
||||||
Set<String> allowableProperties,
|
Set<String> allowableProperties,
|
||||||
Map<String, String> query,
|
Map<String, String> query,
|
||||||
Map<String, Object> extraProps) {
|
Map<String, Object> extraProps) {
|
||||||
|
if (allowableProperties.contains("scheme")) {
|
||||||
|
properties.put("scheme", "" + uri.getScheme());
|
||||||
|
}
|
||||||
if (allowableProperties.contains("host")) {
|
if (allowableProperties.contains("host")) {
|
||||||
properties.put("host", "" + uri.getHost());
|
properties.put("host", "" + uri.getHost());
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,8 @@ public class TransportConstants {
|
||||||
|
|
||||||
public static final String PROTOCOLS_PROP_NAME = "protocols";
|
public static final String PROTOCOLS_PROP_NAME = "protocols";
|
||||||
|
|
||||||
|
public static final String SCHEME_PROP_NAME = "scheme";
|
||||||
|
|
||||||
public static final String HOST_PROP_NAME = "host";
|
public static final String HOST_PROP_NAME = "host";
|
||||||
|
|
||||||
public static final String PORT_PROP_NAME = "port";
|
public static final String PORT_PROP_NAME = "port";
|
||||||
|
@ -362,6 +364,7 @@ public class TransportConstants {
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
allowableAcceptorKeys.add(TransportConstants.PROTOCOL_PROP_NAME);
|
allowableAcceptorKeys.add(TransportConstants.PROTOCOL_PROP_NAME);
|
||||||
allowableAcceptorKeys.add(TransportConstants.PROTOCOLS_PROP_NAME);
|
allowableAcceptorKeys.add(TransportConstants.PROTOCOLS_PROP_NAME);
|
||||||
|
allowableAcceptorKeys.add(TransportConstants.SCHEME_PROP_NAME);
|
||||||
allowableAcceptorKeys.add(TransportConstants.HOST_PROP_NAME);
|
allowableAcceptorKeys.add(TransportConstants.HOST_PROP_NAME);
|
||||||
allowableAcceptorKeys.add(TransportConstants.PORT_PROP_NAME);
|
allowableAcceptorKeys.add(TransportConstants.PORT_PROP_NAME);
|
||||||
allowableAcceptorKeys.add(TransportConstants.KEYSTORE_PROVIDER_PROP_NAME);
|
allowableAcceptorKeys.add(TransportConstants.KEYSTORE_PROVIDER_PROP_NAME);
|
||||||
|
|
Loading…
Reference in New Issue