clebertsuconic commented on a change in pull request #3092: ARTEMIS-2723 Read
the default CLI connector from the related broker
URL: https://github.com/apache/activemq-artemis/pull/3092#discussion_r410721672
##########
File path:
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/ConnectionAbstract.java
##########
@@ -79,6 +95,67 @@ public void setProtocol(String protocol) {
this.protocol = protocol;
}
+ @Override
+ public Object execute(ActionContext context) throws Exception {
+ super.execute(context);
+
+ if (brokerURL == null) {
+ String brokerURLInstance = getBrokerURLInstance();
+
+ if (brokerURLInstance != null) {
+ brokerURL = brokerURLInstance;
+ } else {
+ brokerURL = DEFAULT_BROKER_URL;
+ }
+ }
+
+ System.out.println("Connection brokerURL = " + brokerURL);
+
+ return null;
+ }
+
+ private String getBrokerURLInstance() {
+ if (getBrokerInstance() != null) {
+ try {
+ File xmlFile = new File(new File(getBrokerEtc()), "bootstrap.xml");
+ String configuration = xmlFile.toURI().toString().replace("file:",
"xml:").replace("\\", "/");
+ BrokerDTO brokerDTO =
BrokerFactory.createBrokerConfiguration(configuration, getBrokerHome(),
getBrokerInstance(), getBrokerURIInstance());
+
+ FileConfiguration fileConfiguration = new FileConfiguration();
+ String serverConfiguration =
brokerDTO.server.getConfigurationURI().toASCIIString();
+ FileDeploymentManager fileDeploymentManager = new
FileDeploymentManager(serverConfiguration);
+ fileDeploymentManager.addDeployable(fileConfiguration);
+ fileDeploymentManager.readConfiguration();
+
+ for (TransportConfiguration acceptorConfiguration:
fileConfiguration.getAcceptorConfigurations()) {
+ Map<String, Object> acceptorParams =
acceptorConfiguration.getParams();
+ String protocols =
ConfigurationHelper.getStringProperty(TransportConstants.PROTOCOLS_PROP_NAME,
null, acceptorParams).toUpperCase();
+
+ if (protocols == null ||
protocols.contains(protocol.toUpperCase())) {
+ 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 (scheme.equals(SchemaConstants.VM)) {
Review comment:
if anything failed.. like you can't find the broker.xml on the ETC.. just
use the default option.
That will be true for the cases where you use the CLI from the main
distribution. as a matter of fact you should test the options outside of the
broker instance.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services