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_r410721374
 
 

 ##########
 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:
   why don't you do something simple?
   
   Look for broker.xml on the etc.
   
   look for the acceptor named "artemis"
   
   ```<acceptor 
name="artemis">tcp://0.0.0.0:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;amqpMinLargeMessageSize=102400;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true</acceptor```
   
   
   if you can't find it, just use the DEFAULT and the user will have to be more 
ellaborative on the cli options.
   
   
   no reason to complicate things here IMO.

----------------------------------------------------------------
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

Reply via email to