This is an automated email from the ASF dual-hosted git repository.

jbertram pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new 5b175cb806 ARTEMIS-5388 expose core bridge connection status via JMX
     new 09866a252c This closes #5613
5b175cb806 is described below

commit 5b175cb80660941fdcf6f48229eeb2872346808f
Author: Arthur Naseef <[email protected]>
AuthorDate: Mon Apr 7 08:42:44 2025 -0700

    ARTEMIS-5388 expose core bridge connection status via JMX
---
 .../artemis/api/core/management/BridgeControl.java |   6 +
 .../core/management/impl/BridgeControlImpl.java    |   5 +-
 .../core/server/cluster/impl/BridgeImpl.java       |   2 +-
 .../bridge/BridgeConnectionStatusTest.java         | 123 +++++++++++++++++++++
 4 files changed, 134 insertions(+), 2 deletions(-)

diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/BridgeControl.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/BridgeControl.java
index e056f040d4..8a75358086 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/BridgeControl.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/BridgeControl.java
@@ -140,4 +140,10 @@ public interface BridgeControl extends 
ActiveMQComponentControl {
    @Attribute(desc = "The metrics for this bridge. The 
messagesPendingAcknowledgement counter is incremented when the bridge is has 
forwarded a message but is waiting acknowledgement from the remote broker. The 
messagesAcknowledged counter is the number of messages actually received by the 
remote broker.")
    Map<String, Object> getMetrics();
 
+
+   /**
+    * {@return whether the bridge is actively connected to the remote broker}
+    */
+   @Attribute(desc = "whether the bridge is actively connected to the remote 
broker.")
+   boolean isConnected();
 }
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/BridgeControlImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/BridgeControlImpl.java
index dd431a9149..3aeef93a9e 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/BridgeControlImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/BridgeControlImpl.java
@@ -322,5 +322,8 @@ public class BridgeControlImpl extends AbstractControl 
implements BridgeControl
       }
    }
 
-
+   @Override
+   public boolean isConnected() {
+      return bridge.isConnected();
+   }
 }
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/impl/BridgeImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/impl/BridgeImpl.java
index fd2eb06572..c5b50ff04a 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/impl/BridgeImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/impl/BridgeImpl.java
@@ -352,7 +352,7 @@ public class BridgeImpl implements Bridge, 
SessionFailureListener, SendAcknowled
 
    @Override
    public boolean isConnected() {
-      return session != null;
+      return session != null && !session.isClosed();
    }
 
    /**
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/bridge/BridgeConnectionStatusTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/bridge/BridgeConnectionStatusTest.java
new file mode 100644
index 0000000000..7acd7ed5ad
--- /dev/null
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/bridge/BridgeConnectionStatusTest.java
@@ -0,0 +1,123 @@
+/*
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.tests.integration.bridge;
+
+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.management.BridgeControl;
+import org.apache.activemq.artemis.core.config.BridgeConfiguration;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import 
org.apache.activemq.artemis.core.server.ComponentConfigurationRoutingType;
+import org.apache.activemq.artemis.core.server.cluster.Bridge;
+import 
org.apache.activemq.artemis.tests.extensions.parameterized.ParameterizedTestExtension;
+import 
org.apache.activemq.artemis.tests.integration.management.ManagementControlHelper;
+import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.apache.activemq.artemis.tests.util.Wait;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import javax.management.MBeanServer;
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Test to verify the isConnected() status reported by a Core Bridge correctly 
indicates when the bridge is connected.
+ */
+@ExtendWith(ParameterizedTestExtension.class)
+public class BridgeConnectionStatusTest extends ActiveMQTestBase {
+
+   private ActiveMQServer sourceServer;
+   private ActiveMQServer targetServer;
+
+   private MBeanServer mbeanServer;
+
+   private String getServer0URL() {
+      return "vm://0";
+   }
+
+   private String getServer1URL() {
+      return "vm://1";
+   }
+
+   @Override
+   @BeforeEach
+   public void setUp() throws Exception {
+      super.setUp();
+
+      this.mbeanServer = createMBeanServer();
+
+      sourceServer = createServer(false, createBasicConfig());
+      sourceServer.getConfiguration().addAcceptorConfiguration("acceptor", 
getServer0URL());
+      sourceServer.getConfiguration().addConnectorConfiguration("connector", 
getServer1URL());
+      sourceServer.setMBeanServer(this.mbeanServer);
+
+      targetServer = createServer(false, createBasicConfig());
+      targetServer.getConfiguration().addAcceptorConfiguration("acceptor", 
getServer1URL());
+
+      // Start source but not target
+      sourceServer.start();
+   }
+
+   @Test
+   public void testBridgeConnectionStatus() throws Exception {
+      SimpleString source = SimpleString.of("source");
+      SimpleString target = SimpleString.of("target");
+
+      
sourceServer.createQueue(QueueConfiguration.of(source).setRoutingType(RoutingType.ANYCAST));
+
+      sourceServer.deployBridge(
+          new BridgeConfiguration()
+              .setRoutingType(ComponentConfigurationRoutingType.ANYCAST)
+              .setName("bridge")
+              .setForwardingAddress(target.toString())
+              .setQueueName(source.toString())
+              .setConfirmationWindowSize(10)
+              .setConcurrency(1)
+              .setStaticConnectors(Arrays.asList("connector"))
+              .setReconnectAttempts(-1)
+              .setRetryInterval(100)
+              .setRetryIntervalMultiplier(1.0)
+              .setMaxRetryInterval(100)
+      );
+
+      Bridge bridge = 
sourceServer.getClusterManager().getBridges().get("bridge");
+      assertNotNull(bridge);
+
+      // Use BridgeControl to access the JMX MBean.
+      BridgeControl bridgeControl = 
ManagementControlHelper.createBridgeControl("bridge", this.mbeanServer);
+
+      // Verify not connected at start. Also check via JMX.
+      assertFalse(bridge.isConnected());
+      assertFalse(bridgeControl.isConnected());
+
+      // Start the second server so the bridge can connect and verify 
connection is achieved. Also check via JMX.
+      
targetServer.getConfiguration().addQueueConfiguration(QueueConfiguration.of(target).setRoutingType(RoutingType.ANYCAST));
+      targetServer.start();
+      Wait.assertTrue(bridge::isConnected, 2000, 50);
+      assertTrue(bridgeControl.isConnected());
+
+      // Now stop the second server and verify the bridge reports 
disconnected. Also check via JMX.
+      targetServer.stop();
+      Wait.assertFalse(() -> bridge.isConnected(), 2000, 50);
+      assertFalse(bridgeControl.isConnected());
+   }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to