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

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

                Author: ASF GitHub Bot
            Created on: 29/Jun/21 13:34
            Start Date: 29/Jun/21 13:34
    Worklog Time Spent: 10m 
      Work Description: brusdev commented on a change in pull request #3634:
URL: https://github.com/apache/activemq-artemis/pull/3634#discussion_r660006283



##########
File path: 
artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java
##########
@@ -469,7 +473,45 @@ public void onRemoteOpen(Connection connection) throws 
Exception {
       } catch (Exception e) {
          log.error("Error init connection", e);
       }
-      if (!validateConnection(connection)) {
+
+      boolean redirected = false;
+      if (connectionCallback.getTransportConnection().getRedirectTo() != null) 
{
+         org.apache.activemq.artemis.spi.core.remoting.Connection 
transportConnection = connectionCallback.getTransportConnection();
+         Target target = protocolManager.getServer().getBalancerManager()
+            .getBalancer(transportConnection.getRedirectTo())
+            .getTarget(transportConnection, connection.getRemoteContainer(), 
handler.getSASLResult().getUser());
+
+         if (target != null) {
+            
ActiveMQServerLogger.LOGGER.redirectClientConnection(transportConnection, 
target);
+
+            if (!target.isLocal()) {
+               String host = 
ConfigurationHelper.getStringProperty(TransportConstants.HOST_PROP_NAME, 
TransportConstants.DEFAULT_HOST, target.getConnector().getParams());
+               int port = 
ConfigurationHelper.getIntProperty(TransportConstants.PORT_PROP_NAME, 
TransportConstants.DEFAULT_PORT, target.getConnector().getParams());
+
+               ErrorCondition error = new ErrorCondition();
+               error.setCondition(ConnectionError.REDIRECT);
+               error.setDescription(ConnectionError.REDIRECT.toString());
+               Map<Symbol, String> info = new HashMap<>();
+               info.put(AmqpSupport.NETWORK_HOST, host);
+               info.put(AmqpSupport.PORT, Integer.toString(port));
+               error.setInfo(info);
+               connection.setCondition(error);
+
+               redirected = true;
+            }
+         } else {
+            
ActiveMQServerLogger.LOGGER.cannotRedirectClientConnection(transportConnection);
+
+            ErrorCondition error = new ErrorCondition();
+            error.setCondition(ConnectionError.CONNECTION_FORCED);
+            error.setDescription(ConnectionError.CONNECTION_FORCED.toString());

Review comment:
       @gemmellr yes, the redirect to the local target is a pass through. 
Indeed if target.isLocal() then redirected = false and the connection is 
managed like any old connection would without the balancer, ie the 
`RedirectTest#testSymmetricRedirect` test uses the local targets:
   
https://github.com/brusdev/activemq-artemis/blob/broker_balancers/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/balancing/RedirectTest.java#L221

##########
File path: 
artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java
##########
@@ -469,7 +474,46 @@ public void onRemoteOpen(Connection connection) throws 
Exception {
       } catch (Exception e) {
          log.error("Error init connection", e);
       }
-      if (!validateConnection(connection)) {
+
+      boolean redirected = false;
+      if (connectionCallback.getTransportConnection().getRedirectTo() != null) 
{
+         org.apache.activemq.artemis.spi.core.remoting.Connection 
transportConnection = connectionCallback.getTransportConnection();
+         BrokerBalancer brokerBalancer = 
protocolManager.getServer().getBalancerManager()
+            .getBalancer(transportConnection.getRedirectTo());
+         Target target = brokerBalancer.getTarget(transportConnection,
+            connection.getRemoteContainer(), 
handler.getSASLResult().getUser());
+
+         if (target != null) {
+            
ActiveMQServerLogger.LOGGER.redirectClientConnection(transportConnection, 
target);
+
+            if (!target.isLocal()) {
+               String host = 
ConfigurationHelper.getStringProperty(TransportConstants.HOST_PROP_NAME, 
TransportConstants.DEFAULT_HOST, target.getConnector().getParams());
+               int port = 
ConfigurationHelper.getIntProperty(TransportConstants.PORT_PROP_NAME, 
TransportConstants.DEFAULT_PORT, target.getConnector().getParams());
+
+               ErrorCondition error = new ErrorCondition();
+               error.setCondition(ConnectionError.REDIRECT);
+               error.setDescription(String.format("Connection redirected to %s 
by broker balancer %s", brokerBalancer.getName(), target));

Review comment:
       yes the args are reversed. I'll replace the target.toString() with 
host:port




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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

    Worklog Id:     (was: 616233)
    Time Spent: 4.5h  (was: 4h 20m)

> Broker Balancers
> ----------------
>
>                 Key: ARTEMIS-3365
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-3365
>             Project: ActiveMQ Artemis
>          Issue Type: New Feature
>            Reporter: Domenico Francesco Bruscino
>            Assignee: Domenico Francesco Bruscino
>            Priority: Major
>          Time Spent: 4.5h
>  Remaining Estimate: 0h
>
> This feature adds the broker balancers to distribute the incoming client 
> connections across multiple brokers.
> It provides a native redirection for supported clients and a new management 
> API for other clients. The native redirection can be enabled per acceptor and 
> is supported only for CORE and AMQP clients.
> See the [draft 
> documentation|https://github.com/brusdev/activemq-artemis/blob/broker_balancers/docs/user-manual/en/broker-balancers.md]
>  for further details. 



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

Reply via email to