[ 
https://issues.apache.org/jira/browse/ARTEMIS-2937?focusedWorklogId=503674&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-503674
 ]

ASF GitHub Bot logged work on ARTEMIS-2937:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 22/Oct/20 11:07
            Start Date: 22/Oct/20 11:07
    Worklog Time Spent: 10m 
      Work Description: gemmellr commented on a change in pull request #3294:
URL: https://github.com/apache/activemq-artemis/pull/3294#discussion_r510074183



##########
File path: 
artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/connect/AMQPBrokerConnection.java
##########
@@ -0,0 +1,570 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.artemis.protocol.amqp.connect;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+import org.apache.activemq.artemis.api.core.ActiveMQException;
+import org.apache.activemq.artemis.api.core.Message;
+import org.apache.activemq.artemis.api.core.QueueConfiguration;
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.api.core.TransportConfiguration;
+import 
org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPBrokerConnectConfiguration;
+import 
org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPBrokerConnectionElement;
+import 
org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPBrokerConnectionAddressType;
+import 
org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPMirrorBrokerConnectionElement;
+import org.apache.activemq.artemis.core.postoffice.Binding;
+import org.apache.activemq.artemis.core.postoffice.QueueBinding;
+import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection;
+import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector;
+import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
+import org.apache.activemq.artemis.core.server.ActiveMQComponent;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.server.Consumer;
+import org.apache.activemq.artemis.core.server.Queue;
+import org.apache.activemq.artemis.core.server.impl.AddressInfo;
+import 
org.apache.activemq.artemis.core.server.plugin.ActiveMQServerQueuePlugin;
+import org.apache.activemq.artemis.core.server.remotecontrol.MirrorController;
+import org.apache.activemq.artemis.protocol.amqp.broker.AMQPSessionCallback;
+import 
org.apache.activemq.artemis.protocol.amqp.broker.ActiveMQProtonRemotingConnection;
+import org.apache.activemq.artemis.protocol.amqp.broker.ProtonProtocolManager;
+import 
org.apache.activemq.artemis.protocol.amqp.connect.mirror.AMQPMirrorControllerAggregation;
+import 
org.apache.activemq.artemis.protocol.amqp.connect.mirror.AMQPMirrorControllerSource;
+import 
org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPIllegalStateException;
+import 
org.apache.activemq.artemis.protocol.amqp.logger.ActiveMQAMQPProtocolLogger;
+import org.apache.activemq.artemis.protocol.amqp.proton.AMQPConnectionContext;
+import org.apache.activemq.artemis.protocol.amqp.proton.AMQPSessionContext;
+import 
org.apache.activemq.artemis.protocol.amqp.proton.ProtonServerSenderContext;
+import org.apache.activemq.artemis.protocol.amqp.proton.SenderInitializer;
+import org.apache.activemq.artemis.protocol.amqp.sasl.ClientSASL;
+import org.apache.activemq.artemis.protocol.amqp.sasl.ClientSASLFactory;
+import org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry;
+import 
org.apache.activemq.artemis.spi.core.remoting.ClientConnectionLifeCycleListener;
+import org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManager;
+import org.apache.activemq.artemis.spi.core.remoting.Connection;
+import org.apache.activemq.artemis.utils.ConfigurationHelper;
+import org.apache.activemq.artemis.utils.UUIDGenerator;
+import org.apache.qpid.proton.amqp.Symbol;
+import org.apache.qpid.proton.amqp.messaging.Source;
+import org.apache.qpid.proton.amqp.messaging.Target;
+import org.apache.qpid.proton.engine.Receiver;
+import org.apache.qpid.proton.engine.Sender;
+import org.apache.qpid.proton.engine.Session;
+import org.jboss.logging.Logger;
+
+public class AMQPBrokerConnection implements 
ClientConnectionLifeCycleListener, ActiveMQServerQueuePlugin {
+
+   private static final Logger logger = 
Logger.getLogger(AMQPBrokerConnection.class);
+
+   private final AMQPBrokerConnectConfiguration amqpConfiguration;
+   private final ProtonProtocolManager protonProtocolManager;
+   private final ActiveMQServer server;
+   private final NettyConnector bridgesConnector;
+   private NettyConnection connection;
+   private Session session;
+   AMQPSessionContext sessionContext;
+   ActiveMQProtonRemotingConnection protonRemotingConnection;
+   private volatile boolean started = false;
+   private final AMQPBrokerConnectionManager bridgeManager;
+   private int retryCounter = 0;
+   private volatile ScheduledFuture reconnectFuture;
+   Map<Queue, Sender> senders = new HashMap<>();
+   Map<Queue, Receiver> receivers = new HashMap<>();
+
+   final Executor connectExecutor;
+   final ScheduledExecutorService scheduledExecutorService;
+
+   /** This is just for logging.
+    *  the actual connection will come from the amqpConnection configuration*/
+   String host;
+
+   /** This is just for logging.
+    *  the actual connection will come from the amqpConnection configuration*/
+   int port;
+
+   public AMQPBrokerConnection(AMQPBrokerConnectionManager bridgeManager, 
AMQPBrokerConnectConfiguration amqpConfiguration,
+                               ProtonProtocolManager protonProtocolManager,
+                               ActiveMQServer server,
+                               NettyConnector bridgesConnector) {
+      this.bridgeManager = bridgeManager;
+      this.amqpConfiguration = amqpConfiguration;
+      this.protonProtocolManager = protonProtocolManager;
+      this.server = server;
+      this.bridgesConnector = bridgesConnector;
+      connectExecutor = server.getExecutorFactory().getExecutor();
+      scheduledExecutorService = server.getScheduledPool();
+   }
+
+   public void stop() {
+      if (connection != null) {
+         connection.close();
+      }
+      ScheduledFuture scheduledFuture = reconnectFuture;
+      reconnectFuture = null;
+      if (scheduledFuture != null) {
+         scheduledFuture.cancel(true);
+      }
+      started = false;
+   }
+
+   public void connect() throws Exception {
+      started = true;
+      server.getConfiguration().registerBrokerPlugin(this);
+      try {
+
+         for (AMQPBrokerConnectionElement connectionElement : 
amqpConfiguration.getConnectionElements()) {
+            if (connectionElement.getType() == 
AMQPBrokerConnectionAddressType.mirror) {
+               
installMirrorController((AMQPMirrorBrokerConnectionElement)connectionElement, 
server);
+            }
+         }
+      } catch (Throwable e) {
+         logger.warn(e.getMessage(), e);
+         return;
+      }
+      connectExecutor.execute(() -> doConnect());
+   }
+
+   public NettyConnection getConnection() {
+      return connection;
+   }
+
+   @Override
+   public void afterCreateQueue(Queue queue) {
+      connectExecutor.execute(() -> {
+         for (AMQPBrokerConnectionElement connectionElement : 
amqpConfiguration.getConnectionElements()) {
+            validateMatching(queue, connectionElement);
+         }
+      });
+   }
+
+   public void validateMatching(Queue queue, AMQPBrokerConnectionElement 
connectionElement) {
+      if (connectionElement.getType() != 
AMQPBrokerConnectionAddressType.mirror) {
+         if (connectionElement.getQueueName() != null) {
+            if (queue.getName().equals(connectionElement.getQueueName())) {
+               createLink(queue, connectionElement);
+            }
+         } else if (connectionElement.match(queue.getAddress(), 
server.getConfiguration().getWildcardConfiguration())) {
+            createLink(queue, connectionElement);
+         }
+      }
+   }
+
+   public void createLink(Queue queue, AMQPBrokerConnectionElement 
connectionElement) {
+      if (connectionElement.getType() == AMQPBrokerConnectionAddressType.peer) 
{
+         connectSender(false, queue, queue.getAddress().toString(), 
Symbol.valueOf("qd.waypoint"));
+         connectReceiver(protonRemotingConnection, session, sessionContext, 
queue, Symbol.valueOf("qd.waypoint"));
+      } else {
+         if (connectionElement.getType() == 
AMQPBrokerConnectionAddressType.sender) {
+            connectSender(false, queue, queue.getAddress().toString());
+         }
+         if (connectionElement.getType() == 
AMQPBrokerConnectionAddressType.receiver) {
+            connectReceiver(protonRemotingConnection, session, sessionContext, 
queue);
+         }
+      }
+   }
+
+   private void doConnect() {
+      try {
+         List<TransportConfiguration> configurationList = 
amqpConfiguration.getTransportConfigurations();
+
+         TransportConfiguration tpConfig = configurationList.get(0);
+
+         String hostOnParameter = 
ConfigurationHelper.getStringProperty(TransportConstants.HOST_PROP_NAME, 
TransportConstants.DEFAULT_HOST, tpConfig.getParams());
+         int portOnParameter = 
ConfigurationHelper.getIntProperty(TransportConstants.PORT_PROP_NAME, 
TransportConstants.DEFAULT_PORT, tpConfig.getParams());
+         this.host = hostOnParameter;
+         this.port = portOnParameter;
+         connection = bridgesConnector.createConnection(null, hostOnParameter, 
portOnParameter);
+
+         if (connection == null) {
+            retryConnection();
+            return;
+         }
+
+         reconnectFuture = null;
+         retryCounter = 0;
+
+         // before we retry the connection we need to remove any previous links
+         // as they will need to be recreated
+         senders.clear();
+         receivers.clear();
+
+         ClientSASLFactory saslFactory = null;
+
+         if (amqpConfiguration.getUser() != null && 
amqpConfiguration.getPassword() != null) {
+            saslFactory = availableMechanims -> {
+               if (availableMechanims != null && 
Arrays.asList(availableMechanims).contains("PLAIN")) {
+                  return new PlainSASLMechanism(amqpConfiguration.getUser(), 
amqpConfiguration.getPassword());
+               } else {
+                  return null;
+               }
+            };
+         }

Review comment:
       Fair enough, though not supporting the SASL mechanisms the broker itself 
already does for clients (and so would be required for brokers to connect using 
this feature in such cases) seems bizarre.




----------------------------------------------------------------
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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 503674)
    Time Spent: 16h  (was: 15h 50m)

> AMQP Server Connectivity
> ------------------------
>
>                 Key: ARTEMIS-2937
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-2937
>             Project: ActiveMQ Artemis
>          Issue Type: New Feature
>          Components: AMQP
>            Reporter: Clebert Suconic
>            Assignee: Clebert Suconic
>            Priority: Major
>             Fix For: 2.16.0
>
>          Time Spent: 16h
>  Remaining Estimate: 0h
>
> This feature adds server side connectivity.
>  
> It is possible to link two brokers directly using AMQP with this feature, and 
> have a Queue transferring messages to another broker directly. 
>  
> For this we would have options called <sender and <receiver
>  
>  
> it would also be possible to use qpid-dispatch as an intermediary between 
> clients and the brokers (or eventually between brokers), on that case the 
> option will be <peer
>  
> it would also be possible to use <mirror with a few option to replicate data 
> between two brokers, bringing the possibility of using it for Disaster & 
> Recovery and Failover.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to