Search in sources :

Example 1 with BridgeControl

use of org.apache.activemq.artemis.api.core.management.BridgeControl in project activemq-artemis by apache.

the class ActiveMQServerControlImpl method getBridgeNames.

@Override
public String[] getBridgeNames() {
    checkStarted();
    clearIO();
    try {
        Object[] bridges = server.getManagementService().getResources(BridgeControl.class);
        String[] names = new String[bridges.length];
        for (int i = 0; i < bridges.length; i++) {
            BridgeControl bridge = (BridgeControl) bridges[i];
            names[i] = bridge.getName();
        }
        return names;
    } finally {
        blockOnIO();
    }
}
Also used : BridgeControl(org.apache.activemq.artemis.api.core.management.BridgeControl) JsonObject(javax.json.JsonObject) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 2 with BridgeControl

use of org.apache.activemq.artemis.api.core.management.BridgeControl in project activemq-artemis by apache.

the class BridgeControlTest method testAttributes.

@Test
public void testAttributes() throws Exception {
    checkResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(bridgeConfig.getName()));
    BridgeControl bridgeControl = createBridgeControl(bridgeConfig.getName(), mbeanServer);
    Assert.assertEquals(bridgeConfig.getName(), bridgeControl.getName());
    Assert.assertEquals(bridgeConfig.getDiscoveryGroupName(), bridgeControl.getDiscoveryGroupName());
    Assert.assertEquals(bridgeConfig.getQueueName(), bridgeControl.getQueueName());
    Assert.assertEquals(bridgeConfig.getForwardingAddress(), bridgeControl.getForwardingAddress());
    Assert.assertEquals(bridgeConfig.getFilterString(), bridgeControl.getFilterString());
    Assert.assertEquals(bridgeConfig.getRetryInterval(), bridgeControl.getRetryInterval());
    Assert.assertEquals(bridgeConfig.getRetryIntervalMultiplier(), bridgeControl.getRetryIntervalMultiplier(), 0.000001);
    Assert.assertEquals(bridgeConfig.getReconnectAttempts(), bridgeControl.getReconnectAttempts());
    Assert.assertEquals(bridgeConfig.isUseDuplicateDetection(), bridgeControl.isUseDuplicateDetection());
    String[] connectorPairData = bridgeControl.getStaticConnectors();
    Assert.assertEquals(bridgeConfig.getStaticConnectors().get(0), connectorPairData[0]);
    Assert.assertTrue(bridgeControl.isStarted());
}
Also used : BridgeControl(org.apache.activemq.artemis.api.core.management.BridgeControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 3 with BridgeControl

use of org.apache.activemq.artemis.api.core.management.BridgeControl in project activemq-artemis by apache.

the class BridgeControlTest method testStartStop.

@Test
public void testStartStop() throws Exception {
    checkResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(bridgeConfig.getName()));
    BridgeControl bridgeControl = createBridgeControl(bridgeConfig.getName(), mbeanServer);
    // started by the server
    Assert.assertTrue(bridgeControl.isStarted());
    bridgeControl.stop();
    Assert.assertFalse(bridgeControl.isStarted());
    bridgeControl.start();
    Assert.assertTrue(bridgeControl.isStarted());
}
Also used : BridgeControl(org.apache.activemq.artemis.api.core.management.BridgeControl) Test(org.junit.Test)

Example 4 with BridgeControl

use of org.apache.activemq.artemis.api.core.management.BridgeControl in project activemq-artemis by apache.

the class ManagementServiceImpl method registerBridge.

@Override
public synchronized void registerBridge(final Bridge bridge, final BridgeConfiguration configuration) throws Exception {
    bridge.setNotificationService(this);
    ObjectName objectName = objectNameBuilder.getBridgeObjectName(configuration.getName());
    BridgeControl control = new BridgeControlImpl(bridge, storageManager, configuration);
    registerInJMX(objectName, control);
    registerInRegistry(ResourceNames.BRIDGE + configuration.getName(), control);
}
Also used : BridgeControlImpl(org.apache.activemq.artemis.core.management.impl.BridgeControlImpl) BridgeControl(org.apache.activemq.artemis.api.core.management.BridgeControl) ObjectName(javax.management.ObjectName)

Example 5 with BridgeControl

use of org.apache.activemq.artemis.api.core.management.BridgeControl in project activemq-artemis by apache.

the class ActiveMQServerControlTest method testCreateAndDestroyBridge.

@Test
public void testCreateAndDestroyBridge() throws Exception {
    String name = RandomUtil.randomString();
    String sourceAddress = RandomUtil.randomString();
    String sourceQueue = RandomUtil.randomString();
    String targetAddress = RandomUtil.randomString();
    String targetQueue = RandomUtil.randomString();
    ActiveMQServerControl serverControl = createManagementControl();
    checkNoResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(name));
    assertEquals(0, serverControl.getBridgeNames().length);
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory csf = createSessionFactory(locator);
    ClientSession session = csf.createSession();
    session.createQueue(sourceAddress, RoutingType.ANYCAST, sourceQueue);
    session.createQueue(targetAddress, RoutingType.ANYCAST, targetQueue);
    // forwardingAddress
    serverControl.createBridge(// forwardingAddress
    name, // forwardingAddress
    sourceQueue, // forwardingAddress
    targetAddress, // forwardingAddress
    null, // filterString
    null, // duplicateDetection
    ActiveMQClient.DEFAULT_RETRY_INTERVAL, // duplicateDetection
    ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, // duplicateDetection
    ActiveMQClient.INITIAL_CONNECT_ATTEMPTS, // duplicateDetection
    ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS, // duplicateDetection
    false, // confirmationWindowSize
    1, // producerWindowSize
    -1, // liveConnector
    ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, // liveConnector
    connectorConfig.getName(), false, false, null, null);
    checkResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(name));
    String[] bridgeNames = serverControl.getBridgeNames();
    assertEquals(1, bridgeNames.length);
    assertEquals(name, bridgeNames[0]);
    BridgeControl bridgeControl = ManagementControlHelper.createBridgeControl(name, mbeanServer);
    assertEquals(name, bridgeControl.getName());
    assertTrue(bridgeControl.isStarted());
    // check that a message sent to the sourceAddress is put in the tagetQueue
    ClientProducer producer = session.createProducer(sourceAddress);
    ClientMessage message = session.createMessage(false);
    String text = RandomUtil.randomString();
    message.putStringProperty("prop", text);
    producer.send(message);
    session.start();
    ClientConsumer targetConsumer = session.createConsumer(targetQueue);
    message = targetConsumer.receive(5000);
    assertNotNull(message);
    assertEquals(text, message.getStringProperty("prop"));
    ClientConsumer sourceConsumer = session.createConsumer(sourceQueue);
    assertNull(sourceConsumer.receiveImmediate());
    serverControl.destroyBridge(name);
    checkNoResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(name));
    assertEquals(0, serverControl.getBridgeNames().length);
    // check that a message is no longer diverted
    message = session.createMessage(false);
    String text2 = RandomUtil.randomString();
    message.putStringProperty("prop", text2);
    producer.send(message);
    assertNull(targetConsumer.receiveImmediate());
    message = sourceConsumer.receive(5000);
    assertNotNull(message);
    assertEquals(text2, message.getStringProperty("prop"));
    sourceConsumer.close();
    targetConsumer.close();
    session.deleteQueue(sourceQueue);
    session.deleteQueue(targetQueue);
    session.close();
    locator.close();
}
Also used : ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) BridgeControl(org.apache.activemq.artemis.api.core.management.BridgeControl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Aggregations

BridgeControl (org.apache.activemq.artemis.api.core.management.BridgeControl)6 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 Test (org.junit.Test)4 JsonObject (javax.json.JsonObject)1 ObjectName (javax.management.ObjectName)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)1 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)1 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)1 ActiveMQServerControl (org.apache.activemq.artemis.api.core.management.ActiveMQServerControl)1 BridgeControlImpl (org.apache.activemq.artemis.core.management.impl.BridgeControlImpl)1 Notification (org.apache.activemq.artemis.core.server.management.Notification)1 SimpleNotificationService (org.apache.activemq.artemis.tests.integration.SimpleNotificationService)1